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.

Reply via email to