saranrsm has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks
Problem: Im trying to pre-compile a couple of patterns (Regular expression) and match it into the given text.
Done so far: I have tried doing this without pre-compiled regex, which work perfectly
$text="I have a problem with pre-compiled regex"; @words=qw(have regex); for $a(@words) { while ($text =~ m/$a/g) { print "Found $&\n"; } }
Stuck with: Now when I wanted to pre-compile these patterns (have, regex) and match with $text, I don't get the expected result. I have posted the script which doesn't work, below.
$text="I have a problem with pre-compiled regex"; @words=qw(qr/have/ qr/regex/); for $a(@words) { while ($text =~ /$a/g) { print "Found $&\n"; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Problem with pre-compiled regex
by moritz (Cardinal) on Jan 17, 2012 at 14:16 UTC | |
by saranrsm (Acolyte) on Jan 17, 2012 at 14:42 UTC | |
by moritz (Cardinal) on Jan 17, 2012 at 15:31 UTC | |
by ikegami (Patriarch) on Jan 18, 2012 at 07:03 UTC | |
by JavaFan (Canon) on Jan 17, 2012 at 16:45 UTC | |
by LanX (Saint) on Jan 17, 2012 at 15:14 UTC | |
by JavaFan (Canon) on Jan 17, 2012 at 16:34 UTC | |
Re: Problem with pre-compiled regex
by Anonymous Monk on Jan 17, 2012 at 15:50 UTC |
Back to
Seekers of Perl Wisdom