Paolo Gianrossi wrote:
Hello, Experts!
Hello,
I am into perl since a couple of weeks, so please excuse any
ingenuity ;)
To the problem: I have a regex in a variable, and would like to match
it.
I clearly understand that I can do this:
my $rexp="match";
$text=~m/$rexp/g;
However what i want to do is subtly different: i'd like to do this:
my $rexp="m/match/g";
$text=~$rexp;
The only way to use the /g option like that is to use eval:
my $rexp = 'match';
eval { $text =~ /$rexp/g };
or even
my $rexp="s/match/subst/g";
$text=~$rexp;
Same here with the /g option:
my $rexp = 'match';
my $replace = 'subst';
eval { $text =~ s/$rexp/$replace/g };
Also see:
perldoc -q "How can I expand variables in text strings?"
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/