wrote in news:20050405125614.353$:
> "A. Sinan Unur" <> wrote:
>>
>> In the context of the split function, // matches the empty string.
>>
>> Elsewhere, // means the last successful pattern match.
>>
>> IMHO, the passage above is very clear, but here is the relevant
>> section from perldoc perlop (where m// is being discussed):
>>
>> 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, does anyone find this behavior useful? I've never intentionally
> used it, and I can't imagine doing so in the future.
I can think of one situation where this feature might be useful.
Consider the following:
#! perl
use strict;
use warnings;
my $s = 'one two three onetwo three one two three four';
my %count;
if( $s =~ /\b(one)\b/ or $s =~ /\b(two)\b/ ) {
++$count{$1} while( $s =~ //g );
}
__END__
Here, I am interested in counting the number of times the word 'one' in
the text. If there are no 'one's, then I want to count the number of
times 'two' occurs.
I think this is the most succint way of expressing the intent above. I
do not know if it would offer any speed advantages over other methods of
doing the same thing.
The construct might allow the programmer to more naturally avoid
alternation in regular expressions in favor of or tests in the
conditional and that might result in a performance benefit as well.
All this is speculation, however.
Sinan
--
A. Sinan Unur <>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html