For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > June 2007 > Perl BUG?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Perl BUG?
Mihai Vlad

2007-06-27, 9:59 pm

Tom Phoenix

2007-06-28, 3:59 am

On 6/27/07, Mihai Vlad <mihai.vlad@axigen.com> wrote:

> $a = 'whatever';
> $b = '';
>
> $test = 'x\ y';
> $test =~ s/\\ / /;


This replaces a backslash and a space with a space. But it's also a
successful pattern match, which will matter in a moment.

> if ( $a =~ m/$b/ ) {


What's that pattern? It's not an empty pattern. According to perlop's
entry on m// :

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).

So by using the empty string, you triggered this obscure feature. You
might have wanted something like this for $b to get a true empty
pattern:

my $b = qr/(?#empty)/;

You're not the first person to discover this feature by accident,
though; that's one of the reasons it's been removed in Perl 6.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training
Mihai Vlad

2007-06-28, 3:59 am

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com