[Israel.pm] perl regex operator question

Peter Gordon peter at pg-consultants.com
Sun Jun 27 06:14:19 PDT 2010


Use this to see what the precedence is (Gabor once sent this to me)

perl -MO=Deparse,-p prog.pl

So: 
while (! $line =~ /something/) {
}

while ( $line !~/something/) { 
}

while (! ($line =~/something/)) { 
} 

gets parsed as 


while (((!$line) =~ /something/)) {
    ();
}
while ((not ($line =~ /something/))) {
    ();
}
while ((not ($line =~ /something/))) {
    ();
}

And no, it isn't obvious that the first line is wrong. 

Peter

On Sun, 2010-06-27 at 15:10 +0300, Yossi Itzkovich wrote:
> Hi
> 
>  
> 
> We have a code that didn't work, it is something like:
> 
> While (! $line =~/something/)
> 
> { … }
> 
>  
> 
> It didn't work (I mean it never entered the code block).  We couldn't
> find the problem, so just as trying woodo we changed it into:
> 
>  
> 
> While ( $line !~/something/)
> 
> { … }
> 
>  
> 
> And now it works.  Then we change the original code into :
> 
> While (! ($line =~/something/))
> 
> { … }
> 
>  
> 
> And it works again.  What was the problem with the first version ?  
> 
>  
> 
> Yossi
> 
>  
> 
>  
> 
>  
> 
> 
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://mail.perl.org.il/mailman/listinfo/perl




More information about the Perl mailing list