AnomalousMonk has asked for the wisdom of the Perl Monks concerning the following question:
I'm confused about the behavior of the special match variables ${^PREMATCH} ${^MATCH} ${^POSTMATCH} (see perlvar) in relation to the /p regex modifier, all available in 5.10+. (Note that these are not, AFAIU, the same as the $PREMATCH $MATCH $POSTMATCH variables (again, perlvar), which are just the use English; equivalents of the $` $& $' variables, the notorious '$& and friends'.)
The documentation leads me to believe that ${^MATCH} et al are only valid after a match that uses the /p regex modifier, but the code below produces the same output with or without the /p modifier. What gives?
>perl -wMstrict -le "my $s = '----abc123++++'; $s =~ m{ ([[:alpha:]]+) (\d+) }xms; print qq{'${^PREMATCH}' '${^MATCH}' '${^POSTMATCH}' ($1) ($2)}; " '----' 'abc123' '++++' (abc) (123)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: ${^MATCH} regex special variable(s) and /p regex modifier
by toolic (Bishop) on Oct 04, 2011 at 01:32 UTC | |
|
Re: ${^MATCH} regex special variable(s) and /p regex modifier
by JavaFan (Canon) on Oct 04, 2011 at 07:03 UTC | |
by lidden (Curate) on Oct 04, 2011 at 10:33 UTC | |
by JavaFan (Canon) on Oct 04, 2011 at 11:15 UTC | |
by lidden (Curate) on Oct 04, 2011 at 14:16 UTC | |
|
Re: ${^MATCH} regex special variable(s) and /p regex modifier
by AnomalousMonk (Archbishop) on Oct 05, 2011 at 06:11 UTC |