[prev in list] [next in list] [prev in thread] [next in thread] 

List:       perl5-porters
Subject:    Re: [perl #126749] FH: get more benefit from ||, &&
From:       Abigail <abigail () abigail ! be>
Date:       2015-11-27 13:02:09
Message-ID: 20151127130209.GA28808 () almanda ! fritz ! box
[Download RAW message or body]


[ 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
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic