Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: array of hashes?

by AnomalousMonk (Abbot)
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 +' } } };


Comment on Re: array of hashes?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (18)
As of 2014-09-19 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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











    Results (142 votes), past polls