in reply to s/// with an empty pattern uses the previous pattern of a s///
Yes, this is documented in perlop:
If the PATTERN evaluates to the empty string, the last successfully matched regular expression is used instead. In this case, only the g and c flags on the empty pattern is honoured - the other flags are taken from the original pattern. If no match has previously succeeded, this will (silently) act instead as a genuine empty pattern (which will always match).
If you want to $pat = ''; /$pat/ to match only empty strings, then add $pat = qr/^\z/ if not length($pat);
If you want to $pat = ''; /$pat/ to match everything, then add $pat = qr/.*/ if not length($pat);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: s/// with an empty pattern uses the previous pattern of a s///
by ikegami (Patriarch) on May 17, 2007 at 15:59 UTC | |
by ckeith100 (Initiate) on May 17, 2007 at 16:25 UTC | |
by ikegami (Patriarch) on May 17, 2007 at 17:46 UTC | |
by diotalevi (Canon) on May 17, 2007 at 17:50 UTC | |
by jdporter (Paladin) on May 17, 2007 at 18:16 UTC |