in reply to Why Does My Hash Become Undefined?
use Modern::Perl; use Text::CSV; use Data::Dumper; my $csv = Text::CSV->new () or die "Cannot use CSV: ".Text::CSV->error +_diag (); open my $fh, "<", 'test.csv'; $csv->column_names ($csv->getline ($fh)); my $arrayref = $csv->getline_hr_all ($fh); say Dumper(\$arrayref); # __DATA__ # First,Second,Third # 1,2,3 # One,Two,Three # Een,Twee,Drie
Output:
$VAR1 = \[ { 'Second' => '2', 'Third' => '3', 'First' => '1' }, { 'Second' => 'Two', 'Third' => 'Three', 'First' => 'One' }, { 'Second' => 'Twee', 'Third' => 'Drie', 'First' => 'Een' } ];
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|
|---|