develooper Front page | perl.perl5.porters | Postings from March 2011

Re: [perl #85822] precedence "and" "ne" does not match precedencedeclared in perlop

Thread Previous
From:
Paul Johnson
Date:
March 10, 2011 11:13
Subject:
Re: [perl #85822] precedence "and" "ne" does not match precedencedeclared in perlop
Message ID:
20110310191258.GA3422@pjcj.net
On Thu, Mar 10, 2011 at 03:53:19AM -0800, badrazat@ncbi.nlm.nih.gov wrote:

> perl -e 'print 1 and "+" ne "+"; print "\n"'
> 1
> 
> while it should give "", because the precendence of "ne" is higher than "and". Instead it computes 1 and "+" which gives 1, and
> compares it to "+" which gives 1 again.

I'm afraid this does neither what you expect nor what you think it is doing.
Instead, it is parsed as:

  ( print 1 ) and ( "+" ne "+" )

Adding -MO=Deparse,-p is fairly informative here:

$ perl -MO=Deparse,-p -e 'print 1 and "+" ne "+"; print "\n"'
(print(1) and '???');
print("\n");
-e syntax OK

I suggest re-reading the start of perlop.

Recommend closing this as not a bug.

-- 
Paul Johnson - paul@pjcj.net
http://www.pjcj.net

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About