Front page | perl.fwp |
Postings from February 2005
Re: "Secret" operators
Thread Previous
|
Thread Next
From:
philippe.bruhat
Date:
February 1, 2005 09:54
Subject:
Re: "Secret" operators
Message ID:
20050201175210.GA7780@localhost.localdomain
Le mardi 01 février 2005 à 17:40, José Castro écrivait:
> * Ronald J Kimball (rjk-perl-fwp@tamias.net) wrote:
> > You can assign two elements to a one-element list:
> >
> > ($foo) = (1, 2);
> >
> > You can even assign two elements to an empty list:
> >
> > () = (1, 2);
> >
> >
> > In each case, any extra elements are simply discarded, but the result of
> > the assignment in scalar context is always the number of elements on the
> > right-hand side, even if some aren't actually assigned to variables.
>
> Which is why this:
>
> perl -e '$_ = ($foo) = (1, 2) ; print'
>
> prints out 2.
I think a better example is :
$ perl -e '$_ = ($foo) = (1,3); print'
2
versus
$ perl -e '$_ = $foo = (1,3); print'
3
There you can see how () was useful, and be reminded that a list in
scalar context returns its last element.
--
Philippe "BooK" Bruhat
The right answer is worthless with the wrong question!
(Moral from Groo The Wanderer #88 (Epic))
Thread Previous
|
Thread Next