in reply to CSV Files With Missing Values
I couldn't resist implementing the `real-life-example':
#!/pro/bin/perl use strict; use warnings; use IO::Handle; use Text::CSV_XS; open my $fh, "<", "data.csv" or die "data.csv: $!"; my $csv = Text::CSV_XS->new ({ binary => 1, eol => "\r\n" }); $csv->types ([ Text::CSV_XS::PV (), # Server Text::CSV_XS::IV (), # Count ]); while (my $row = $csv->getline ($fh)) { my ($server, @data) = @$row; $csv->print (*STDOUT, $row); } close $fh;
Note however, the you still got the warnings:
# cat data.csv CSFDATVM01,,2.55,3.77 # perl data.pl Argument "" isn't numeric in subroutine entry at xx.pl line 17, <$fh> +line 1. CSFDATVM01,0,2.55,3.77 #
But at least, you reached your goal in a reliable way
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: CSV Files With Missing Values
by Zen (Deacon) on Jul 23, 2007 at 14:09 UTC | |
by Tux (Canon) on Jul 23, 2007 at 14:19 UTC | |
by Zen (Deacon) on Jul 23, 2007 at 14:29 UTC | |
by ww (Archbishop) on Jul 23, 2007 at 15:59 UTC | |
|