in reply to Re^2: ??{ } oddity
in thread ??{ } oddity
It will be executed each time the regex is looked at (compiled), even if the match doesn't get that far. For example:
Contrast that with (?{}), which executes arbitrary code if the expression matched up to that point (and does not insert anything into your pattern):for (qw{dog pig cat horse}) { /.o${print "$_ gets printed\n";\''}/ and print "$_ matched\n"; } __END__ dog gets printed dog matched pig gets printed cat gets printed horse gets printed horse matched
And finally (??{}), which acts the same, but does insert into your pattern:for (qw{dog pig cat horse}) { /.o(?{print "$_ gets printed\n"})/ and print "$_ matched\n"; } __END__ dog gets printed dog matched horse gets printed horse matched
The latter two are "experimental" features, but ref interpolation is not.for (qw{dog pig cat horse}) { /.o(??{print "$_ gets printed\n"; 'g'})/ and print "$_ matched\n"; } __END__ dog gets printed dog matched horse gets printed
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: ??{ } oddity
by insaniac (Friar) on Apr 28, 2005 at 17:09 UTC |