in reply to Printing hash of a hash data

Hi,

You can easily get that done like so:

#!/usr/bin/perl use warnings; use strict; my %my_hash = ( 'James' => { 'detection_profile' => 'disable' }, 'Bob' => { 'detection_profile' => 'enable', 'detection_profile_severity' => '180' }, 'Billy' => { 'detection_profile' => 'enable', 'detection_profile_severity' => '180' }, 'Stephanie' => { 'detection_profile' => 'enable', 'detection_profile_severity' => '180' }, ); foreach my $detective ( keys %my_hash ) { print $detective; while ( my ( $key, $value ) = each $my_hash{$detective} ) { print " ", $value; } print $/; }

output
Stephanie enable 180 James disable Bob enable 180 Billy enable 180
please, you might also like to check perldsc

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

Replies are listed 'Best First'.
Re^2: Printing hash of a hash data
by eanicom (Initiate) on Sep 17, 2012 at 22:31 UTC

    hello i attempted to execute your snippet in order to explore but i got the following error:

    Type of arg 1 to each must be hash (not hash element) at ./test.pl line 24, near "} ) " Execution of ./test.pl aborted due to compilation errors.

      Try:
      while ( my ( $key, $value ) = each %{ $my_hash{$detective} }) {

                   I hope life isn't a big joke, because I don't get it.
                         -SNL