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


Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^2: CSV Files With Missing Values
by Zen (Deacon) on Jul 23, 2007 at 14:09 UTC
    What's causing that warning?

      use warning; does, but it has nothing to do wit CSV

      # perl -wle'print ""+0' Argument "" isn't numeric in addition (+) at -e line 1. 0 #

      On a more important note, the original data reveiled an error in Text::CSV_XS, which I just fixed in 0.31, which has already been sent to CPAN.


      Enjoy, Have FUN! H.Merijn
      Hmm ok, but I'm still interested in how to solve that warning. It's a tough sell to recommend code that gives warnings especially when you can't understand why.
        ...when you can't understand why
        is a pretty strong hint that you need to read the docs... or at least search for a few of the many threads here where the explanation and (quasi-) legitimate workarounds abound.
        A reply falls below the community's threshold of quality. You may see it by logging in.