http://www.perlmonks.org?node_id=1059930


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