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

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1059930]
[chacham]: How many man-hours would you estimate you have invested in learning Perl? what an annoying poll
[chacham]: s/annoying/ugly

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2017-04-30 20:56 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (542 votes). Check out past polls.