On 8/1/11 Mon  Aug 1, 2011  11:20 AM, "Rob Dixon" <rob.di...@gmx.com>
scribbled:

> On 01/08/2011 19:00, Dr.Ruud wrote:
>> On 2011-08-01 15:52, Shlomi Fish wrote:
>> 
>>> To convert a string to characters one can use split based on the empty
>>> regex,
>> 
>> That should be "a pattern matching the empty string".
>> 
>> The "empty regex" works differently:
>> 
>> perl -wle '
>> my $text = "abcdefghi";
>> $text =~ /[aeiou]/;
>> $text =~ /x/;
>> my @result = $text =~ //g;
>> print "@result";
>> '
>> a e i
>> 
>> (admire how 'regex' and 'regular expression' are avoided in perldoc -f
>> split)
> 
> Please Shlomi, you have taught me nothing despite repeated reading of
> your post. Please tell me what is wrong with the OP's
> 
>> To convert a string to characters one can use split based on the empty regex
> 
> Are you trying to say that any regular expression that can match zero
> character will also suffice? How does your code demonstrate the point
> you are making?

Rob:

I believe you are responding to Dr. Ruud's post, not Shlomi's, and the term
"empty regex" is Shlomi's, not the OP (Emeka).

Dr. Ruud is demonstrating the little-known but documented feature of Perl
that the explicit empty regex // repeats the last, successful regex within
its scope. Thus, in Dr. Ruud's sample program, the line

  my @result = $text =~ //g;

is equivalent to the line

  my @result = $text =~ /[aeiou]/g;

because that was the regex used in the last successful match.

Of course, in a beginner's list, it is better to explain such exceptional
cases, rather than just showing the statements. or people may miss the point
entirely. But not everyone has the time or inclination to do so,
unfortunately.



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to