Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

CSV_XS issue

by wassmp1 (Initiate)
on Sep 04, 2013 at 18:49 UTC ( #1052418=perlquestion: print w/ replies, xml ) Need Help??
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?

Comment on CSV_XS issue
Select or Download Code
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?

      I don't get any errors 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!

        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 . . .

        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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1052418]
Approved by davido
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (17)
As of 2014-07-23 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (145 votes), past polls