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

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

Thread Previous | Thread Next
November 27, 2015 13:02
Re: [perl #126749] FH: get more benefit from ||, &&
Message ID:

[ Snip ]

> Second suprise:
>     people on irc said
>     truth is a scalar concept. it can't work at all otherwise.
>     @y = (0,1);
>     print "@y"   if @y = @y; # (0,1) <--- Why this works?? it is list, not scalar

You aren't clear what "it" in "it is list" refers to. The statement has
several sub expressions, some in scalar context, others in list context.

The if statement evaluates its argument in scalar context. Its argument
is a list assignment. The value of a list assignment in scalar context
is the number of elements on the LHS of the assigment. (This is what

    my $matches = () = $str =~ /(foo)/g;

makes work).

[ Snip ]


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About