http://www.perlmonks.org?node_id=1052418

wassmp1 has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to parse a CSV file using TEXT::CSV_XS. The following code runs fine on Windows:

use strict; use warnings; use Text::CSV_XS; my $csv = Text::CSV_XS->new ({auto_diag => 1, binary => 1 }); my $infile_name = "DeviceTrim.csv"; open my $CSV_INPUT, "<", $infile_name or die "$infile_name: $!"; my $row = $csv->getline ($CSV_INPUT);

But when I run it on Linux I get the message:

Can't call method "getline" on an undefined value at DeviceTrimGen.pl +line 7.

Any ideas?

Replies are listed 'Best First'.
Re: CSV_XS issue
by Anonymous Monk on Sep 04, 2013 at 19:20 UTC

    That means $csv is undef.

    What error do you get during the ->new operation?

      You're reply pointed me in the right direction - even though there were no error messages when I invoked ->new, I discovered that there is a diagnostic facility available if the "new" constructor fails. When I included it:

      my $csv = Text::CSV_XS->new ({ binary => 1 }) or die "".Text::CSV_XS->error_diag();

      It informed me that I was using an unsupported argument. Further investigation showed that the Linux version of CSV_XS was older than the Windows version, and apparently does not support the same set of arguments.

      Thanks for your help!

        auto_diag was added back in version 0.66, which was back in Aug 2009. If you are using a version that old, there are a lot of bugs to encounter still.

        You might have picked up the new (better) invocation from documentation not on your system. Reading docs from any resource other than the box your module is installed might always lead to inconsistencies.


        Enjoy, Have FUN! H.Merijn

        Yep... I was beginning to get suspicious.   Turns out that you were comparing Apples to Oranges, not Windows to Linux.   Please tell us what version of CSV_XS is installed on each, e.g.:

        perl -e 'use CSV::XS; print "CSV::XS->VERSION" . "\n";

        Insofar as possible, Perl is very much an “environment agnostic” programming tool.   But, heh, those environments sure can get interesting . . .

      I don't get any errors during the ->new operation.