Hello Anonymous Monk,
It seems that the fellow Monks have already answered your question. Every now and then I try to add minor step to add something extra.
If you want to get the key and value for each hash element you can use each. Also it will help you a lot to debug your complex elements with Data::Dumper.
Sample of code:
#!/user/bin/perl use strict; use warnings; use Data::Dumper; use feature 'say'; my %hash = ( "00:00:00" => "a", "00:20:00" => "a", "10:00:00" => "b", "20:00:00" => "a", "02:22:00" => "b", ); my %hash2 = ( "00:00:00" => "a", "00:20:00" => "a", "10:00:00" => "b", "20:00:00" => "a", "02:22:00" => "b", ); my @bla = (\%hash, \%hash2); # print Dumper \@bla; foreach my $array_hash_element ( @bla ) { # reset the internal iterator so a prior each() doesn't affect the + loop keys %$array_hash_element; say $array_hash_element; # to see when the next hash will come in while( my ( $key , $value ) = each %$array_hash_element) { say "Key: $key, Value: $value"; } } __END__ $ perl test.pl HASH(0x55a097458d28) Key: 20:00:00, Value: a Key: 00:00:00, Value: a Key: 00:20:00, Value: a Key: 02:22:00, Value: b Key: 10:00:00, Value: b HASH(0x55a097470488) Key: 02:22:00, Value: b Key: 10:00:00, Value: b Key: 20:00:00, Value: a Key: 00:00:00, Value: a Key: 00:20:00, Value: a
Hope this helps, BR.
In reply to Re: Using foreach to iterate through a hash in an array
by thanos1983
in thread Using foreach to iterate through a hash in an array
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |