nneul has asked for the wisdom of the Perl Monks concerning the following question:
$pat = "something with (.*?) in it"; $re = qr/$pat/; if ( $line =~ $re ) (or /$re/, same results) { $1 has nothing in it here. nor does $& or $` if ( $line =~ /$pat/ ) { $1 has the matched text in it here } }
The matches will occur orders of magnitude less frequently than the number of uses of the pattern, so the above code still helps performance dramatically, but it's ugly. (I'm trying to avoid taking the step of generating the code and eval'ing when qr// seems to almost do the job.)
I'm using 5.8.1 built from cpan tarball on rh9.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Is there any way to get at paren matches from qr//
by eserte (Deacon) on May 13, 2004 at 15:56 UTC | |
by nneul (Novice) on May 13, 2004 at 16:06 UTC | |
by dave_the_m (Monsignor) on May 13, 2004 at 16:09 UTC | |
by nneul (Novice) on May 13, 2004 at 16:13 UTC | |
by nneul (Novice) on May 13, 2004 at 16:09 UTC |