Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: array of hashes?

by 2teez (Priest)
on Oct 27, 2013 at 19:50 UTC ( #1059930=note: print w/ replies, xml ) Need Help??

in reply to array of hashes?

Hi Mark.Allan,

Any assistance on how I could generate..

The data structure you have is not array of hashes as your title suggested and as it has been rightly pointed out. Your data structure as presented is HASHES OF HASHES, atleast as far as I can see.

..and print this data structure..
If I may give you a head up, something like this can do for your OP dataset, of course, please give heed to the advises of the monks who had commented before now.

use warnings; use strict; use Data::Dumper; my %com = ( 'mode' => { 'switch1' => { 'type' => ' auto mode for switch1', 'action' => ' completed with assistance.' }, 'switch2' => { 'type' => ' auto mode for switch2', 'action' => 'completed on own.' }, 'switch3' => { 'type' => ' auto mode for switch3', 'action' => ' rasied alarm, incident reported.' }, 'switch4' => { 'type' => ' manual mode for switch4', 'action' => ' complete process manually', }, }, ); # this shows what you have originally # with sorted keys though { local $Data::Dumper::Sortkeys = 1; print Dumper %com; } # you can print out on your own foreach my $key ( sort keys %com ) { print $key, $/; check_and_print( $com{$key} ); } sub check_and_print { my $val = shift; if ( ref $val eq 'HASH' ) { for my $key ( sort keys %{$val} ) { print q{ }, $key, $/; check_and_print( $val->{$key} ); } } else { print q{ }, $val, $/; } }

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

Comment on Re: array of hashes?
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2015-11-30 17:10 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (777 votes), past polls