Beefy Boxes and Bandwidth Generously Provided by pair Networks
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.

UPDATE

I think analyzing the op-tree helps understanding the mechanism

lanx@nc10-ubuntu:~/org$ perl -MO=Terse -e'$x= ()=qw(a,b)' LISTOP (0x9bd0fe0) leave [1] OP (0x9be01e8) enter COP (0x9bb8860) nextstate BINOP (0x9b3ca48) sassign BINOP (0x9b21a58) aassign [2] UNOP (0x9b218c0) null [142] OP (0x9be3e40) pushmark SVOP (0x9c14638) const [3] PV (0x9b1dee0) "a,b" UNOP (0x9c14598) null [142] OP (0x9b19820) pushmark OP (0x9b3c980) stub UNOP (0x9be8630) null [15] PADOP (0x9b21940) gvsv GV (0x9b1dec0) *x -e syntax OK

(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
in thread Using grep and glob to find directories containing file by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-04-26 07:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found