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

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

Thread Previous | Thread Next
From:
Abigail
Date:
November 27, 2015 13:02
Subject:
Re: [perl #126749] FH: get more benefit from ||, &&
Message ID:
20151127130209.GA28808@almanda.fritz.box

[ 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 ]



Abigail

Thread Previous | Thread Next


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