in reply to Re: Get all hash value into array
in thread Get all hash value into array

> most simple solution

Simplest? I doubt that, but it's maybe the shortest.

And your solution depends on the assumption that the array fields have always a fixed index.

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

Replies are listed 'Best First'.
Re^3: Get all hash value into array
by leszekdubiel (Scribe) on Feb 02, 2020 at 13:30 UTC

    Yess... if data structures are more structured then program gets more safe and precise:

    #!/usr/bin/perl use utf8; use Modern::Perl; use Data::Dumper; my $db = { '99155' => { 'PR' => { state_name => 'Puerto Rico', county_names_all => [qw{Adjuntas Utuado}], }, 'AK' => { state_name => 'Alaska', county_names_all => ['Ketchikan', 'Gateway', +'Prince of + Wales-Hyder'], }, 'WA' => { state_name => 'Washington', county_names_all => ['Pend Oreille', 'Spokane +', 'Lincol +nAdams'], comments => 'America/Los_Angeles' } }, '26134' => { 'WV' => { state_name => 'West Virginia', county_names_all => ['Wirt', 'Wood', 'Jackso +n', 'Ritchie', 'Calhoun'], comments => 'America/New_York' } } }; my %states_with_comments = map { ($$_{state_name}, 'hurray!') } grep { $$_{comments} } map { values %$_ } values %$db; print "states are: ", (join "; ", sort, keys %states_with_comments), " +\n";

    Dumper of db:

    $VAR1 = { '26134' => { 'WV' => { 'county_names_all' => [ 'Wirt', 'Wood', 'Jackson', 'Ritchie', 'Calhoun' ], 'comments' => 'America/New_York', 'state_name' => 'West Virginia' } }, '99155' => { 'WA' => { 'comments' => 'America/Los_Angeles', 'state_name' => 'Washington', 'county_names_all' => [ 'Pend Oreille +', 'Spokane', 'Lincol +nAda +ms' ] }, 'AK' => { 'county_names_all' => [ 'Ketchikan', 'Gateway', 'Prince of + +Wales-Hyder' ], 'state_name' => 'Alaska' }, 'PR' => { 'state_name' => 'Puerto Rico', 'county_names_all' => [ 'Adjuntas', 'Utuado' ] } } };