On Wed, Oct 09, 2002 at 03:22:20PM -0700, nkuipers wrote:

> The following is from page 75 in the Camel:
> 
> "List assignment in scalar context returns the number of elements produced by 
> the expression on the <i>right</i> side of the assignment:
> 
> $x = ( ($a, $b) = (7,7,7) ); #set $x to 3, not 2
> 
> ...."
> 
> why.  how.

Note that this is the same as

    $x = ($a, $b) = (7,7,7);

= is right associative.

($a, $b) = (7,7,7) you already understand.  This is the list assignment
mentioned above.  It is in a scalar context because of the assignment to
$x, which is a scalar.  But "the right side of the assignment" is still
talking about the list assignment, and thus $x gets the number of
elements in (7,7,7), which is 3, not ($a, $b) which would be 2.

This allows you to do useful things like

  $x = () = some_function;

which evaluates some_function in list context, and sets $x to the number
of elements returned.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to