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

Re: array of hashes?

by AnomalousMonk (Chancellor)
on Oct 27, 2013 at 15:16 UTC ( #1059914=note: print w/replies, xml ) Need Help??

in reply to array of hashes?

... assistance on how I could ... print this data structure ...

A way to better print the data structure during development and debug (and when communicating with your fellow monks) is to properly use structure dumping tools like Data::Dumper and Data::Dump. For instance, you show one dump as

$VAR1 = 'mode'; $VAR2 = { 'type' => ' auto mode', 'action' => ' completed on own.' };
which suggests a statement like
    print Dumper %hash;
was used to generate it. This use of Dumper and its siblings and cousins such as dd in Data::Dump flattens out the top-level key/value pairs of the hash into a representation that quickly becomes incomprehensible, IMHO, for large structures (although I think dd does a bit better with it than Dumper).

Properly passing the structure by reference leads to a much more comprehensible representation. Ferinstance:

>perl -wMstrict -le "use Data::Dumper; ;; my %component = ( 'mode' => { 'type' => ' auto mode', 'action' => ' completed on own.', }, 'mood' => { 'switch1' => { 'type' => ' auto mode for switch1', 'action' => ' completed with assistance.', }, 'switch2' => { 'type' => ' auto mode for switch2', 'action' => 'completed on own.', }, }, ); ;; print Dumper \%component; " $VAR1 = { 'mode' => { 'action' => ' completed on own.', 'type' => ' auto mode' }, 'mood' => { 'switch2' => { 'action' => 'completed on own.', 'type' => ' auto mode for switch2 +' }, 'switch1' => { 'action' => ' completed with assi +stance.', 'type' => ' auto mode for switch1 +' } } };

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1059914]
[choroba]: Will Glasgow have been out of the EU by that time already?
[LanX]: nope
hippo might venture to YAPC::EU.
[choroba]: YAPC::YAEC (yet another European country)
[LanX]: they are proposing an infinite transition phase now ...
[choroba]: infinite transition implies infinite money!
[LanX]: ... ehm ..."open ended" ;-)

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2018-02-23 10:57 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (301 votes). Check out past polls.