Hi,

Be aware that you have a small problem.
Your script includes:
for (my $j=1;$j<$#rows;$j++)
...
for (my $i=0;$i<$#columns;$i++)

I think It should be 
for (my $j=1;$j<=$#rows;$j++)
...
for (my $i=0;$i<=$#columns;$i++)


Cheers

Yaron Kahanovitch
----- Original Message -----
From: [EMAIL PROTECTED]
To: "pauld" <[EMAIL PROTECTED]>
Cc: "beginners" <beginners@perl.org>
Sent: 19:47:38 (GMT+0200) Africa/Harare שבת 26 מאי 2007
Subject: Re: accesing a hash of an array of hashes



Hi,

To access element of a given DATE (sat ... date_inp) from Hofdates you can do 
the following:

my $date_inp = ... ;
die "No etries for date $date_inp" unless (exists $Hofdates{$date_inp} and 
@{$Hofdates{$date_inp}});
foreach my $hash_ref (@{$Hofdates{$date_inp}}) {
    while (my ($field,$value) = each %$hash_ref) {
          print "Fieal = $field, value = $value\n";
     }
}

Hope that helps


Yaron Kahanovitch


----- Original Message

 -----
From: "pauld" <[EMAIL PROTECTED]>
To: beginners@perl.org, [EMAIL PROTECTED]
Sent: 14:17:57 (GMT+0200) Africa/Harare שבת 26 מאי 2007
Subject: accesing a hash of an array of hashes

ive read a load of data in  from a CSV file with Text::CSV and ended
up with a hash (%hash) where the keys are the column labels.
my  @headings=split(/,/,$rows[0])
and then

for (my $j=1;$j<$#rows;$j++)
{
my $status  = $csv->parse ($rows[$j]);   # parse a CSV string into
fields
my @columns = $csv->fields ();           # get the parsed fields

for (my $i=0;$i<$#columns;$i++)
  {$hash{$headings[$i]}=$columns[$i];}

I want to  process the data once its grouped by the date field present
in $hash. So i think I want a hash of dates  where the key is that
date field
I  push onto the value the hashes of the records that contain the date

push @{$Hofdates{$hash{DATE}}},\%hash;

but im having a problem working out how to access the  individual
items in the  hashes that are elements of the array


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to