in reply to Get all hash value into array

> I am able to manage to create the data structure as below

An unfortunate format. :(

Your task would be much easier, if you created a hash of hashes of hashes ...

$VAR1 = { '99155' => { 'PR' => { state_name => 'Puerto Rico', county_names_all => 'Adjuntas|Utuado', }, ...

If your primary source was an array database, consider using proper queries to get what you desire.

UPDATE

moved lengthy update to separate reply below

Replies are listed 'Best First'.
Re^2: Get all hash value into array (while/each)
by LanX (Saint) on Feb 01, 2020 at 13:50 UTC
    Above data structure you can easily be traversed with three nested while loops applying each .

    my $VAR1 = { '99155' => { 'PR' => { state_name => 'Puerto Rico', county_names_all => 'Adjuntas|Utuado', }, }, }; my $v0 = $VAR1; while ( my ($k1,$v1) = each %$v0 ) { while ( my ($k2,$v2) = each %$v1 ) { while ( my ($k3,$v3) = each %$v2 ) { print "\$VAR1->{$k1}{$k2}{$k3} => '$v3'\n" } } }

    output

    $VAR1->{99155}{PR}{state_name} => 'Puerto Rico' $VAR1->{99155}{PR}{county_names_all} => 'Adjuntas|Utuado'

    Since your third level is an array you'll have to split it up into a hash.

    my $v2 = [ 'state_name=Puerto Rico', 'county_names_all=Adjuntas|Utuado', ]; my %h3 = map { split /=/,$_,2 } @$v2; print Dumper \%h3;

    $VAR1 = { 'state_name' => 'Puerto Rico', 'county_names_all' => 'Adjuntas|Utuado' };

    This should give you enough hints. :)

    HTH!

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

    update

    on a side note, you can also use each on arrays

    my $v2 = [ 'state_name=Puerto Rico', 'county_names_all=Adjuntas|Utuado', ]; while ( my ($k3,$v3) = each @$v2 ) { print "\$v2->[$k3] => '$v3'\n" }
    out
    $v2->[0] => 'state_name=Puerto Rico' $v2->[1] => 'county_names_all=Adjuntas|Utuado'