>
> It is always better to post a complete, short, working program rather than a
> snippet.
>

Maybe this will make it more clear as to what I am trying to
accomplish. I simply want to test to see if @hours exists as a second
key in the hash of hashes %data.
If it does not print \t otherwise print the value of the hash.

Sorrry still trying to wrap my head around iterating through a nested
referenced hash.

Thank you,

Chris

#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;



my %data =(

         '149' => {
                    '05' => '1',
                    '06' => '1',
                    '00' => '1',
                    '01' => '2',
                    '03' => '2',
                    '04' => '2'
                  },
         '077' => {
                    '05' => 'ND',
                    '06' => 'ND',
                    '00' => 'ND',
                    '01' => 'ND',
                    '02' => 'ND',
                    '04' => 'ND'
                  },
         '078' => {
                    '05' => '1',
                    '06' => '1',
                    '00' => '1',
                    '01' => '1',
                    '02' => '1',
                    '03' => '1',
                  },

);

my $href = \%data;
my @wanted = qw(077 078 149);
my @hours = qw(00 01 02 03 04 05 06);


foreach my $cell ( @wanted ) {
  print  "$cell:";
  foreach my $hr ( @hours ) {
    if ( defined keys %{ $href->{$hr}}){
      print  "\t$href->{$cell}{$hr}";
    }
    else {
      print  "\t";
    }
  }
  print  "\n";
}

output:
Use of uninitialized value in concatenation (.) or string at
./example.pl line 46.
077:    ND      ND      ND              ND      ND      ND
Use of uninitialized value in concatenation (.) or string at
./example.pl line 46.
078:    1       1       1       1               1       1
Use of uninitialized value in concatenation (.) or string at
./example.pl line 46.
149:    1       2               2       2       1       1

-- 
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