----- Original Message -----
From: Chris Charley <[EMAIL PROTECTED]>
Date: Monday, January 10, 2005 12:59 pm
Subject: Re: complex data structure

> I hope someone can explain this related question. When I run the 
> code below 
I can try, I personaly perfer RoHoH..., looks like you have RoHoAoH

> on Brano's data structure, 'each' gives me false results 
Does it ?? Remember each will not itterate on Data sets. It simply returns key 
and value. 


> but 'keys' gives me correct results. I'm kind of stumped!
because 'keys' itterates over data structures. 

test1[0] is a referance to a 2 key hash, since you called 'each' only once, you 
only got to see first part of the data set :). Here is some code to explain it, 
let me know if you need more help.

#!PERL

use warnings;
use strict;
use Data::Dumper;
use ERRNO;
$|=1; 

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}}) {
print $anon,":\n";
        print join ' ',each %$anon,"\n";
        print join ' ',each %$anon,"\n";
}



> 
> #!/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>
> 
> 
> 


-- 
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