Paolo Gianrossi wrote:
Alright! This works... I solved the minor issue of modifiers and simple
matching instead of substitution (remember I need to take care of
*arbitrary* regexes) by:
my ($op, $replacement, $modifiers)=('', '');
if($rexp=~/^s(.)/){
$op='s';
my $delimiter=quotemeta($1);
(undef, $rexp, $replacement, $modifiers) = split /$delimiter/, $rexp;
if($modifiers) { $rexp = "(?$modifiers)$rexp";}
} else { ... # match other operations alike}
{no warnings 'regexp'; # this I need because I force /g... If user
# enters /g as well, a warning (useless /g) is
# raised.
if($op eq 's') { #substitution... do something similar in
# elsif branches for other ops
while($text =~ s/$regex/$replacement/g){
my $l=length($`);
print substr($text, 0, $l);
print ">";
print substr($text, $l);
}
}
}
So this is fine. The minor issue I see is that this works great with all
delimiters but matching ones. Something in the lines of s(exp)(subs)
fails miserably... Still, I can survive with that.
It also doesn't work if there is whitespace between the operator name
and the delimiter, for example: 'm / abc /x' or 's / abc /def/x'.
Or if the delimiter is part of the pattern, for example: 'm/..\/..\/../'.
Or if the /e option is used with the substitution operator.
(Or perhaps if the user wants to use tr/// instead of m// or s///?)
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/