On Mon, 2008-09-01 at 10:13 +0200, Paolo Gianrossi wrote:
> Hello, Experts!
>
> 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;
>
> or even
>
> my $rexp="s/match/subst/g";
> $text=~$rexp;
>
> Actually the latter is the reason why I'd like to do this: I'd like the
> user to be able to enter a perl regex and have it run on some text I
> have.
>
> Any clue?
You can pre-compile a regular expression match but not a substitution.
my $rexp = qr/match/;
See `peldoc perlop` and search for "Quote and Quote-like Operators"
Also see:
perldoc perlretut
perldoc perlre
--
Just my 0.00000002 million dollars worth,
Shawn
"Where there's duct tape, there's hope."
Cross Time Cafe
"Perl is the duct tape of the Internet."
Hassan Schroeder, Sun's first webmaster
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/