Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: trying to print hashes with mixed results

by parv (Vicar)
on Apr 09, 2021 at 02:03 UTC ( #11131036=note: print w/replies, xml ) Need Help??


in reply to trying to print hashes with mixed results

You could use Data::Dumper ...

use Data::Dumper; ... while( my ( $k, $v ) = each %hash ) { print Dumper( { qq[error:$k] , $v } ); }

Replies are listed 'Best First'.
Re^2: trying to print hashes with mixed results
by merrittr (Novice) on Apr 09, 2021 at 02:36 UTC
    Sure that will work , but just from a learning standpoint how could I get that loop work and print the values?

      From your output you are; it's just the values are themselves hashrefs. You'd need to then iterate over those in turn. The simplest solution is going to be to use Data::Dumper (or YAML::XS or JSON::PP or . . .).

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

      > but just from a learning standpoint how could I get that loop work and print the values?

      you are looping over a hash-ref and $v is another hash-ref, again.

      so start another loop over $v.

      In the general case you'll need a recursive function which loops over hash-refs and array-refs.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

      Sure that will work , but just from a learning standpoint how could I get that loop work and print the values?

      See Hashes of Hashes in perldsc.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2022-11-26 13:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?