in reply to CSV Columns: Friend or foe?
Never start down the road leading to failure: parse CSV files with split.
Text::CSV_XS and Text::CSV already do your quest in an easy and reliable way:
$ cat test.pl #!/pro/bin/perl use strict; use warnings; use autodie; use Text::CSV_XS; my $csv = Text::CSV_XS->new ({ binary => 1 }); open my $fh, "<", "test.csv"; $csv->column_names ($csv->getline ($fh)); while (my $h = $csv->getline_hr ($fh)) { print "$h->{Name} => $h->{Cost}, $h->{Inventory}\n"; } $ cat test.csv Name,Cost,Inventory pickles,2.99,12 vegemite,4.00,8 nuclear sub,22.50,4 $ perl test.pl pickles => 2.99, 12 vegemite => 4.00, 8 nuclear sub => 22.50, 4 $
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: CSV Columns: Friend or foe?
by Tux (Canon) on Dec 01, 2010 at 13:47 UTC |