On Thu, May 29, 2008 at 11:55 PM, Shmuel Fomberg <[EMAIL PROTECTED]> wrote:
> Hi All.
>
> Can anyone tell me why this line is OK:
> ok( ( $hash->{a} == 7 ) && ( $hash->{b} == 256 ) ,
> "Struct: Build: correct elements");
>
> While this line:
> ok( ( $hash->{a} == 7 ) and ( $hash->{b} == 256 ) ,
> "Struct: Build: correct elements");
> cause a warning:
> Useless use of numeric eq (==) in void context
> ?
[EMAIL PROTECTED]:~$ perl -MO=Deparse a.pl
use warnings;
ok($$hash{'a'} == 7 && $$hash{'b'} == 256, 'Struct: Build: correct elements');
ok($$hash{'a'} == 7 && ($$hash{'b'} == 256, 'Struct: Build: correct elements'));
Or in words:
&& has higher precedence than the comma after the condition while
'and' has lower precedence.
Then the $$hash{'b'} == 256 has no consequence so it is "useless".
Gabor
--
Gabor Szabo http://szabgab.com/blog.html
Perl Training in Israel http://www.pti.co.il/
Test Automation Tips http://szabgab.com/test_automation_tips.html
_______________________________________________
Perl mailing list
[email protected]
http://perl.org.il/mailman/listinfo/perl