in reply to Re: Hash problem
in thread Hash problem
You say that @array2 contains "this kind of data":
(Note that it is possible and preferable to use <code> tags around data samples as well as code snippets.)"0451524934","1984",7.9500,67,"Penguin Putnam" "0618056815","42nd Parallel",13.0000,25,"Houghton Mifflin" "0195167929","A Strange Likeness - Becoming Red and White in Eighteent +h Century",29.9500,0,"Oxford University Press" "0520204026","Abortionist : A Woman Against the Law",25.0000,30,"Unive +rsity of California Press"
Looks like you want to parse each element as CSV data, because it's possible that some of the quoted fields may contain commas, and a simple regex will have trouble with that. Text::CSV will probably be what you want:
(I'm expecting that Text::CSV will remove the quotes that surround some field values, but if it doesn't, you can handle that easily enough.)use Text::CSV; # ... load data into @array2 my $csv = Text::CSV->new(); for my $line ( @array2 ) { if ( $csv->parse( $line )) { my @fields = $csv->fields; $Tex{$fields[0]} = \@fields; # or maybe you want this instead? : # $Tex{$fields[0]} = [ @fields[1..$#fields] ]; } else { warn "CSV parse error on: $line\n"; } }
|
|---|