Re: Perl forgets variable every other pass in loop???



On 2008-08-28, John W. Krahn <someone@xxxxxxxxxxx> wrote:

That is the way that each() works.

From perldoc -f each:

When the hash is entirely read, a null array is
returned in list context (which when assigned pro-
duces a false (0) value), and "undef" in scalar
context. The next call to "each" after that will
start iterating again.

So the ''forgotten'' entries are the null arrays.

--keith



--
kkeller-usenet@xxxxxxxxxxxxxxxxxxxxxxxxxx
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information

.



Relevant Pages

  • Re: Parsing a string into a hash
    ... documents what happens when m// is used in a list context: ... You have chosen an extremely poor data structure for your strings. ... an infathomable one-liner. ... A => "Array ...
    (comp.lang.perl.misc)
  • Re: script to find most common last names in a file
    ... splitreturns a list in list context so you need list context on the *left* ... store its results in the @_ array. ... Unlike in normal regular expressions * is *not* greedy in split's regular ... > # then creat a hash table of first and last names, ...
    (perl.beginners)
  • Re: help with array within another array
    ... here you're pushing to an array that perl has never heard of, @SESSION, ... so perl goes ahead and makes an empty one for you before it pushes your ... (A hash in list context is just a list.) ...
    (perl.beginners)
  • Re: script to find most common last names in a file
    ... John W. Krahn wrote: ... > splitreturns a list in list context so you need list context on the ... > splitwill store its results in the @_ array. ... >> # then creat a hash table of first and last names, ...
    (perl.beginners)
  • Re: beginners-help@perl.org
    ... The output from the system command may be better stored in a scalar and then ... split into an array. ... the qx// operator in list context returns the output as a list ... This is an extremely bad idea (for one thing, strict would ...
    (perl.beginners)