in reply to grep trouble
Passing an empty string in $_ creates an empty regexp pattern, as in "m//". This is a special case discussed in perlop, here:
The empty pattern //
If the PATTERN evaluates to the empty string, the last successfully matched regular expression is used instead.....If no match has previously succeeded, this will (silently) act instead as a genuine empty pattern (which will always match).
Your first match occurs in that vacuum of acting like a genuinely empty pattern, which will always match. The final test is like asking if "" =~ m/foo/, which doesn't match.
Dave
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: grep trouble
by LanX (Saint) on Apr 17, 2011 at 14:03 UTC | |
by davido (Cardinal) on Apr 17, 2011 at 16:08 UTC | |
by LanX (Saint) on Apr 17, 2011 at 16:21 UTC | |
by John M. Dlugosz (Monsignor) on May 14, 2011 at 16:09 UTC | |
Re^2: grep trouble
by LogMiner (Novice) on Apr 17, 2011 at 14:04 UTC | |
by LanX (Saint) on Apr 17, 2011 at 15:45 UTC | |
by LanX (Saint) on Apr 18, 2011 at 10:37 UTC |
In Section
Seekers of Perl Wisdom