Array of Hashes : Array Hash « Array « Perl






Array of Hashes

   

my $petref = [   { "name"  => "Jack",
                   "type"  => "dog"
                 },
                 { "name"  => "Tom",
                   "type"  => "cat"
                 }
             ];

print "$petref->[0]->{name}.\n";
for($i=0; $i<2; $i++){
    while(($key,$value)=each %{$petref->[$i]} ){
       print "$key -- $value\n";
    }
    print "\n";
}

   
    
    
  








Related examples in the same category

1.Adding a hash to the array