|Next||Regular Expression Mastery||28|
# $s contains a line of code: $s = '($label =~ tr/.//) < 3; # do not attach these';
# Let's strip out comments $s =~ s/#.*//;
$s is now:
'($label =~ tr/.//) < 3; '
If it weren't greedy, $s would be:
'($label =~ tr/.//) < 3; do not attach these';
Suppose * were nongreedy by default....
To get the expected behavior, you'd have to say
# In the parallel universe where * is nongreedy $s =~ s/#.*$//;
But that would be inefficient because it would backtrack on every character!
|Next||Copyright © 2002 M. J. Dominus|