go ahead... be a heretic | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
> Lists don't return their length in scalar context
Correct! With "goatse" it's a list _assignment_ = which in scalar context returns the number of list elements assigned. But this was a scalar assignment. > my $x = ('a', 'b', 'c'); The LHS of the assignment operator decides about the context. An example of scalar context of list context of assignment is while ( ($v,$k) = each %h ) It will terminate as soon as each returns an empty list, not when the lists last element (here $k) is undef. Clearer now?
Cheers Rolf PS: you replied to yourself twice.
UPDATEI think analyzing the op-tree helps understanding the mechanism
(don't blame me for Larry's decision to call a list assignment aassign) You see assignment BINOP is like a function called with arguments (RHS,LHS) and RHS is evaluated according to LHS context and assigned to LHS. (thats decided a compile time) The RHS of the first BINOP is the second BINOP, not a list.
In reply to Re^6: Using grep and glob to find directories containing file (list assignment)
by LanX
|
|