develooper Front page | perl.perl5.porters | Postings from November 2015

Re: [perl #126749] FH: get more benefit from ||, &&

Thread Previous
From:
Zefram
Date:
November 27, 2015 12:44
Subject:
Re: [perl #126749] FH: get more benefit from ||, &&
Message ID:
20151127124428.GK13455@fysh.org
KES wrote:
>But what about DWIM (Do What I Mean) principle?

perl can't guess what you meant in all cases.  At some point you have to
write what you mean.  In this area, the language semantics are consistent,
and we can't change it because of stability requirements.

>First surprise: why the short form does not work whereas long does?

The short form essentially tries to put the single mention of the array
into two different contexts.  The long form has two mentions, so there's
no problem about them getting two contexts.

>    print "@y"   if @y = @y; # (0,1) <--- Why this works?? it is list, not scalar

It's a list assignment, so the assignment operands are in list context,
but the assignment itself is in scalar context.  perlop(1) says

#                               a list assignment in scalar context returns
#      the number of elements produced by the expression on the right hand
#      side of the assignment.

Please stop sending your tutorial questions to perlbug.  This is a venue
for reporting bugs in the perl core; the fact that some of the language
semantics surprise you is not a bug in perl.

-zefram

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