On 2011-07-14 14:09, Mohan L wrote:

I am trying some thing like to print  :

foreach my $line (keys %region_data)
{
     print "$line\n";
     foreach my $item (keys %{$region_data {$line}})
     {
             print "$item\n";
     }
}

Output :

south
status
total_count
north
status
total_count
west
status
total_count
east
status
total_count

But I don't know how to print next level.  I need someone help to point
right direction.

#!/usr/bin/perl
use strict;
use warnings;

my %data = (
 south => {
  status => {
   open => { count => 3 },
   pws => { count => 3 },
   wip => { count => 0 },
   hold => { count => 1 },
   're-open' => { count => 0 },
   pwu => { count => 0 },
   openesc => { count => 0 },
  },
  total_count => 7,
 },

 north => {
  status => {
   open => { count => 3 },
   pws => { count => 0 },
   wip => { count => 0 },
   hold => { count => 7 },
   're-open' => { count => 0 },
   pwu => { count => 0 },
   openesc => { count => 0 },
  },
  total_count => 10,
 },
);

my @items = qw/ open pws wip hold re-open pwu openesc /;

print join( "\t", "region", @items, "total_count" ), "\n";

for my $region ( sort keys %data ) {
  my $d = $data{ $region };
  print join( "\t", $region,
                    map( $d->{ status }{ $_ }{ count }, @items ),
                    $d->{ total_count },
        ), "\n";
}

__END__


Output:

region open pws wip hold re-open pwu openesc total_count
north  3    0   0   7    0       0   0       10
south  3    3   0   1    0       0   0       7

--
Ruud

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to