On May 27, 4:37 pm, [EMAIL PROTECTED] (Pauld) wrote:
> thanks for the help - im looking up hash slices -
perldoc perldata
Entire arrays (and slices of arrays and hashes) are denoted
by '@', which works much like the word "these" or "those"
does in English, in that it indicates multiple values are
expected.
@days # ($days[0], $days[1],... $days[n])
@days[3,4,5] # same as ($days[3],$days[4],$days[5])
@days{'a','c'} # same as ($days{'a'},$days{'c'})
> but id like to get
> something that works and then i can add new ideas etc so im going to
> leave it as it for the time being.
>
> Data::Dumper has helped sort out where an error is coming
>
> #!/usr/bin/perl -w
> use strict;
> use warnings;
> open O, "<$file" or die "could not open $file - $!";
> undef $/;
> my $whole_file = <O>;
> close O;
> $whole_file=~s/\x0D\x0A1/\x0D\x0AABC1/g;my @rows=split(/\x0D\x0AABC/,
> $whole_file);
> ######splits in the correct place after looking at the CSV file with a
> hex editor - ugly but it seems to work ATM######
absolutely no idea what's making you think any of this is necessary.
> my %hash;
> my @headings=split(/,/,$rows[0])
> for (my $j=1;$j<=2;$j++)
> {
> my @columns = $csv->fields ();
>
> for (my $i=0;$i<=$#columns;$i++) {$hash{$headings[$i]}=$columns[$i];}
>
> print Dumper(%hash);
> push (@{$Hofdates{$hash{OPDATE}}},\%hash);
> print Dumper (%Hofdates);
>
> }
>
<output snipped>
> so its pushing the second hash onto the array and overwriting the
> 1st
No kidding. Did you read my reply? That's exactly what I said would
happen. Declare your hash in the smallest scope possible - inside the
(first) for loop. That way, when each iteration of the for loop
starts, you get a brand new hash rather than reusing the same one.
If you don't understand what that means - move the 'my %hash;' line
from where it is to just before the 'my @columns = $csv->fields ();'
line.
Paul Lalli
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/