T
Thomas Randall
I have been given a project to complete regarding Perl regular
expressions. I need to evaluate a given regular expression and
evaluate its effect on a string and compare to the effects of a list
of common functions and identify a match so that a Perl function may
be automatically generated with an appropriate name to encapsulate the
regex.
For example:
$out =~ s/^\s*//;
$out =~ s/\s*$//;
These two lines will trim white space from the front and back of the
string $out. This is equivalent to the function Trim() which can be
found in many languages and function libraries.
I need to write a subroutine such that:
print conversion('s/^\s*//','s/\s*$//');
will generate the output: Trim()
of course I need to be able to match and reduce all regex's to their
equivalent common function name or return undef if there is no
conversion possible.
From there I will need to generate a perl module file containing the
Trim function which will wrap the regex. I think I can do this part
with no problem.
I would greatly appreciate any advice as to where to start on this
project. I admit that it is a question on our take home final exam,
so of course I do not ask for too much help, but a pointer in the
right direction would be greatly appreciated. The professor did allow
us to ask for help on usenet with confidence that we would not be
spoon fed an answer or that at least he could check up on us.
Tom
expressions. I need to evaluate a given regular expression and
evaluate its effect on a string and compare to the effects of a list
of common functions and identify a match so that a Perl function may
be automatically generated with an appropriate name to encapsulate the
regex.
For example:
$out =~ s/^\s*//;
$out =~ s/\s*$//;
These two lines will trim white space from the front and back of the
string $out. This is equivalent to the function Trim() which can be
found in many languages and function libraries.
I need to write a subroutine such that:
print conversion('s/^\s*//','s/\s*$//');
will generate the output: Trim()
of course I need to be able to match and reduce all regex's to their
equivalent common function name or return undef if there is no
conversion possible.
From there I will need to generate a perl module file containing the
Trim function which will wrap the regex. I think I can do this part
with no problem.
I would greatly appreciate any advice as to where to start on this
project. I admit that it is a question on our take home final exam,
so of course I do not ask for too much help, but a pointer in the
right direction would be greatly appreciated. The professor did allow
us to ask for help on usenet with confidence that we would not be
spoon fed an answer or that at least he could check up on us.
Tom