[Israel.pm] Useless use of eq
Gabor Szabo
szabgab at gmail.com
Fri May 30 06:26:57 EEST 2008
On Thu, May 29, 2008 at 11:55 PM, Shmuel Fomberg <semuelf at 012.net.il> 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
> ?
gabor at notebook:~$ 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
More information about the Perl
mailing list