develooper Front page | perl.fwp | Postings from February 2005

Re: "Secret" operators

Thread Previous | Thread Next
From:
Quantum Mechanic
Date:
February 1, 2005 11:55
Subject:
Re: "Secret" operators
Message ID:
20050201195500.13466.qmail@web14021.mail.yahoo.com

--- Bernie Cosell <bernie@fantasyfarm.com> wrote:

> On 1 Feb 2005 at 12:36, Ronald J Kimball wrote:
> 
> > ... A list assignment in scalar context
> > returns the number of elements on the right-hand
> side of the assignment.
> 
> Which is an odd inconsistency, because in list
> context a list assignment 
> returns the left-hand-side-list, so you might guess
> that in scalar 
> context it'd return the number of elements in the
> lhs list...

It seems there are multiple contexts flying around.
I'm no expert, but it seems to develop this way:

$foo = $bar = (9,8,7);

    RHS list
    $bar scalar
    $bar <- 7 (last element of list)
    $foo <- 7

$foo = ($bar) = (9,8,7);

    RHS list
    ($bar) array
    $bar <- 7 (rest discarded)
    $foo <- 3, size of RHS of ($bar) assignment

Therefore,

$foo = () = (9,8,7)

    RHS list
    () array
    no assignment targets, but...
    $foo <- 3, size of RHS of () assignment

My assumption is that =()= creates an intermediate
assignment, which subtley shifts the context so that
$foo gets the count of (9,8,7) in the last case,
instead of the last element of (9,8,7) as in the first
case. 

=()= forks the assigment flow. The elements of the
right operand are assigned (if possible) to the
contained array, as in

    $foo = ($bar) = (9,8,7);
or
    $foo = @bar   = (9,8,7);

The left operand of =()= is assigned the element count
of the other assignment.

Someone familiar with the core will have to clue me in
on the accuracy of my theory.

-QM


=====
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quantum Mechanics: The dreams stuff is made of


		
__________________________________ 
Do you Yahoo!? 
The all-new My Yahoo! - Get yours free! 
http://my.yahoo.com 
 


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