On Sunday 27 Jun 2010 15:10:37 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 ?
>
The problem was precedence. ! has a higher precedence than =~ and so the line
gets evaluated to << while ((! $line) =~ /something/) >>. So either use
parentheses, use the "nor" operator or use "!~".
Regards,
Shlomi Fish
> Yossi
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
Interview with Ben Collins-Sussman - http://shlom.in/sussman
God considered inflicting XSLT as the tenth plague of Egypt, but then
decided against it because he thought it would be too evil.
Please reply to list if it's a mailing list post - http://shlom.in/reply .
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl