Front page | perl.fwp |
Postings from February 2005
Re: "Secret" operators
Thread Previous
|
Thread Next
From:
Yitzchak Scott-Thoennes
Date:
February 1, 2005 13:48
Subject:
Re: "Secret" operators
Message ID:
20050201214832.GA2280@efn.org
On Tue, Feb 01, 2005 at 01:20:21PM -0500, Bernie Cosell 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...
But the lhs usually either has a fixed number of elements or includes
arrays/hashes so the number of elements is arbitrarily large. Using
the rhs allows common idioms like:
while (my ($k, $v) = each %hash) {
}
Here list-context each returns 2 elements (a key/value pair) until the
hash is exhausted, whereupon it returns 0 elements, terminating the loop.
Thread Previous
|
Thread Next