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.

Seeking for Perl wisdom...on the process of learning...not there...yet!

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.