Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: trying to print hashes with mixed results

by parv (Parson)
on Apr 09, 2021 at 02:03 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-03-28 15:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found