On Nov 10, SATAR VAFAPOOR said:

>When I run the following code(with any hash), I get a contiuous stream of
>output. The presence of the array in the loop causes the contiuous stream
>of output. When the array is commented out an output is generated. Why
>does the presence of the array cause a contiuous stream of output. Thanks
>
>while (($k,$v)= each %ENV)
>{
>  @ks=keys %ENV;
>  print "$k     $v\n";
>}

First of all, there's no need to build a list of the keys in the hash IN
EACH ITERATION.  You're better off doing:

  my @keys = keys %ENV;
  while (($k,$v) = each %ENV) { ... }

I'm also not sure why you're using each() if you're going to store the
keys in an array.

But your PRIMARY problem is stated in the documentation of keys() and
each().  From perldoc -f keys:

  As a side effect, it resets HASH's iterator.

and from perldoc -f each:

  that will start iterating again.  There is a single iterator
  for each hash, shared by all "each", "keys", and "values" func-
  tion calls in the program; it can be reset by reading all the
  elements from the hash, or by evaluating "keys HASH" or "values
  HASH".

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]








-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to