in reply to How to set variable names using Text::CSV?
I will only comment on the flaws in script 1, as that deals with Text::CSV
use strict; use warnings; use Text::CSV; use Data::Dumper; open my $io, "<", "player_characters.csv" or die "player_characters.cs +v: $!"; my $csv = Text::CSV_XS->new ({ sep_char => "|", allow_whitespace => 1, blank_is_undef => 1, binary => 1, auto_diag => 1, }); my @names = @{$csv->getline ($io)}; $csv->column_names (@names); while (defined (my $hr = $csv->getline_hr ($io))) { print Dumper ($hr); }
If you do not use the @names after you set it, other than to assign to to column names, you can combine the in one call, as column_names () accepts both a list or a list ref
$csv->column_names ($csv->getline ($io));
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to set variable names using Text::CSV?
by Lady_Aleena (Priest) on Oct 16, 2009 at 06:32 UTC | |
by Tux (Canon) on Oct 16, 2009 at 06:47 UTC | |
by Anonymous Monk on Oct 18, 2009 at 11:11 UTC | |
by Tux (Canon) on Oct 19, 2009 at 12:45 UTC |