Strange Perl pattern matching
Julien ÉLIE
julien at trigofacile.com
Sat Jul 4 16:11:36 UTC 2009
Hi Matija,
> On Sat, Jul 04, 2009 at 11:33:26AM +0200, Julien ÉLIE wrote:
>> And the following is fine:
>>
>> next if ($ngname !~ /$newsgrouppats/);
>> print "A\n";
>> next if ($exclusionpats and $ngname =~ /$exclusionpats/);
>> print "B\n";
>> next if ($droppats and $ngname =~ /$droppats/);
>> print "C\n";
>
> perlop(1) for m/PATTERN/msixpogc says:
>
> "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)."
>
> so that is probably the problem.
Oh, yes, thanks for having pointed me that feature!
As the third condition is executed only if the regexp for $newsgrouppats *matches*
and the one for $exclusionpats does not match, it always matches when there is the
first condition.
I see that Perl6 will change that behaviour: an empty pattern will always match.
http://dev.perl.org/perl6/rfc/144.html
--
Julien ÉLIE
« Some joys are better expressed in silence as a smile holds more meaning
than words. »
More information about the inn-workers
mailing list