Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: iterate through a hash with two keys

by LanX (Canon)
on Apr 29, 2013 at 17:50 UTC ( #1031270=note: print w/ replies, xml ) Need Help??


in reply to Re^2: iterate through a hash with two keys
in thread iterate through a hash with two keys

> I didn't ask the question properly.

indeed!

> I want to print all the labels and values for each of a .. h

DB<103> @hash{$_} = {x=>$x++,y=>$x++} for a..h => "" DB<112> while ( my ($k1,$v1) = each %hash ) { while ( my ($k2,$v2) = each %$v1 ) { print "$k1 - $k2 -$v2\n" } } e - y -25 e - x -24 a - y -17 a - x -16 d - y -23 d - x -22 ... # and so on

But are you looking for Data::Dumper ?

UPDATE

DB<106> print Dumper \%hash $VAR1 = { 'e' => { 'y' => 9, 'x' => 8 }, 'a' => { 'y' => 1, 'x' => 0 }, 'd' => { 'y' => 7, 'x' => 6 }, 'c' => { 'y' => 5, 'x' => 4 }, ...

FWIW I prefer Data::Dump or YAML, but Data::Dumper is core.

Cheers Rolf

( addicted to the Perl Programming Language)

) interesting Module::Build::YAML was first released with perl 5.009004

UPDATE YAML
DB<106> use YAML::Tiny => 0 DB<107> Dump(\%hash) --- a: x: 16 y: 17 b: x: 18 y: 19 c: x: 20 y: 21 d: x: 22 y: 23 ...


Comment on Re^3: iterate through a hash with two keys
Select or Download Code
Re^4: iterate through a hash with two keys
by fionbarr (Pilgrim) on Apr 29, 2013 at 18:32 UTC
    doing it like this:
    my @array = qw( FirstName LastName MiddleName LegalInd DateOfBirth Sex Race Ethnicity Height Weight Build Eyes Hair SocSecNo MaritalStatus PlaceOfBirthCit +y PlaceOfBirthState AddressType DfAdate StreetNumber StreetName StreetType City State Zip ); for (@array) { $xml_writer->dataElement("$_" => $t{A}{$_}); }
      > doing it like this

      Doing what?

      (Do you speak English?)

      Look I've shown you code iterating thru the whole structure.

      If you can't express your problem in proper words, you are still free to adapt the two nested loops to your needs.

      Cheers Rolf

      ( addicted to the Perl Programming Language)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1031270]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2014-09-30 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (384 votes), past polls