After creating a "Hash of Arrays", how can I later access the individual
elements of the Array values? 

Have tried various constructs from "Programming Perl", and "Perl Cookbook",
but can't extrapolate them into code that works - probably because my brain
is fossilized.

Thanks,

Hew

Hewlett M. Pickens
B I Moyle Associates, Inc.

---------------
>From program that creates the DB
....
my %hashStats;
my $dbStats = "hewDBstats";                          
unless (dbmopen %hashStats, $dbStats, 0666)
  {                                               
    print "HEW008 - Cannot open $dbStats \n"; 
    exit 12;                                     
  }       
....                                         

# this line is part of a loop that writes 6 array entries.
# $statsIn[2] is a time stamp.

%hashStats =($statsIn[2] => [@statsIn] ); 
....
unless (dbmclose %hashStats)                     
  {                                              
    print "HEW009 - Cannot close $dbStats \n";
  }   
....
....
---------------------
ls hewDBstats.db shows: 12288 Feb  7 21:33 hewDBstats.db

---------------------

>From program reading the file/database (not all attempts are shown):
....
use Data::Dumper;
my $dbStats = "hewDBstats";                                 
dbmopen my %hashStats, $dbStats, 0666                       
   or die "HewTrace002 - cannot open $dbStats for input \n";
....
---------------------
print Dumper(%hashStats);       # gives the following
                                # key is the time, value is ARRAY ...
$VAR1 = '19:45:56';         
$VAR2 = 'ARRAY(0x4a68d4)';  
$VAR3 = '19:46:40';         
$VAR4 = 'ARRAY(0x4a68d4)';  
$VAR5 = '19:46:51';         
$VAR6 = 'ARRAY(0x4a68d4)';  
$VAR7 = '19:46:07';         
$VAR8 = 'ARRAY(0x4a68d4)';  
$VAR9 = '19:46:18';         
$VAR10 = 'ARRAY(0x4a68d4)'; 
$VAR11 = '19:46:29';        
$VAR12 = 'ARRAY(0x4a68d4)'; Y
-----------------
# this code gives the following (which except for the "Y"
# on the $VAR12, correspondes to Dumper output of values):
while  ((my $keyStats, my $valueStats) = each(%hashStats))
  {                                                       
    print "$keyStats has value of $valueStats \n";        
  }                             

HewTrace003 - from "while loop" at bottom of PP pg 281
19:45:56 has value of ARRAY(0x4a68d4)               
19:46:40 has value of ARRAY(0x4a68d4)               
19:46:51 has value of ARRAY(0x4a68d4)               
19:46:07 has value of ARRAY(0x4a68d4)               
19:46:18 has value of ARRAY(0x4a68d4)               
19:46:29 has value of ARRAY(0x4a68d4)


-------------------          

# If I do this, I get a compile time message:

while  ((my $keyStats, my $valueStats) = each(%hashStats))
  {                                                       
    print "$keyStats has value of $valueStats \n";        
    print "$valueStats[1] \n";                            
  }        

Global symbol "@valueStats" requires explicit package name at hewtest.pl
line 20
# Line 20 is the print $valueStats[1]

------------------

# If I do this, I get a compile time message:

while  ((my $keyStats, my $valueStats) = each(%hashStats))
  {                                                       
    print "$keyStats has value of $valueStats \n";
    my @testArray = @valueStats;
    print "$valueStats[1] \n";   
  }     

Global symbol "@valueStats" requires explicit package name at hewtest.pl
line 21

-----------------
# and, finally, tried this:

print $valueStats->{$keyStats}, "\n";

and got:  Global symbol "@valueStats" requires explicit package name at
hewtest.pl line 21
                               
                   

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to