Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: array of hashes?

by 2teez (Vicar)
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
Domain Nodelet?
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 exploiting the Monastery: (4)
As of 2022-08-08 21:53 GMT
Find Nodes?
    Voting Booth?

    No recent polls found