On May 26, 1:51 pm, [EMAIL PROTECTED] (Mumia W.)
wrote:
> On 05/26/2007 07:17 AM, pauld wrote:
>
> > 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
>
> You don't check $status to see if the parse succeeded.
>
> > my @columns = $csv->fields ();           # get the parsed fields
>
> > for (my $i=0;$i<$#columns;$i++)
> >   {$hash{$headings[$i]}=$columns[$i];}
>
> Now %hash contains the data for the last record processed; however, data
> from any previous records have been obliterated.
>
> > 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
>
> The module Data::Dumper can help you see what's in your hash, but you
> need to rethink how you initialize the first hash (%hash).

So long as the OP declares his %hash in the for loop, there's nothing
wrong with how it's initialized.  The OP did not show where he's
declaring it, unfortunately.  If he made the mistake of declaring it
outside the for loop, then he's adding multiple copies of the same
hash to the array, and that single hash is going to be repeatedly
changed through the program.

Paul Lalli


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


Reply via email to