I hope someone can explain this related question. When I run the code below on Brano's data structure, 'each' gives me false results but 'keys' gives me correct results. I'm kind of stumped!

#!/usr/bin/perl
use strict;
use warnings;

my $hash = {
         'test1' => [
                      {
                        'test1_a' => 'a',
                        'test1_b' => 'b'
                      },
                      {
                        'test1_a' => 'a',
                        'test1_b' => 'b'
                      },
                      {
                        'test1_c' => 'c'
                      },
                      {
                        'test1_d' => 'd'
                      }
                    ]
       };

for my $anon (@{$hash->{test1}}) {
  for (my ($k, $v) = each %$anon) {
     print "$k: $v\n";
  }
  print "### EACH ###\n";
}
print "\n\n";
for my $anon (@{$hash->{test1}}) {
  for (keys %$anon) {
     print "$_: $anon->{$_}\n";
  }
  print "### KEYS ###\n";
}

__END__
(This is what prints out)
C:\perlp>perl t1.pl    # my command line
test1_a: a
test1_a: a
### EACH ###
test1_a: a
test1_a: a
### EACH ###
test1_c: c
test1_c: c
### EACH ###
test1_d: d
test1_d: d
### EACH ###


test1_a: a test1_b: b ### KEYS ### test1_a: a test1_b: b ### KEYS ### test1_c: c ### KEYS ### test1_d: d ### KEYS ###

C:\perlp>



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to