http://qs321.pair.com?node_id=850554

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

Hello Monks,

I have been away from Perl for a while and now have been asked to update a script I worked on a while back. It is a very simple script that takes an uploaded CSV file and updates records/adds new records.

It was working well until recently we started getting the following error Execution ERROR: Can't call method "getline" on an undefined value at ../../local-lib/DBD/CSV.pm line 427.

I have tried updating all of the modules I use locally, used different versions of DBD::CSV in case it was specific to one version and verified that the file is uploaded correctly and accessible to my script.

I thought it was a problem accessing the CSV, but I can open it and dump it to the browser without any trouble. I am a little out of practice and appreciate any input on how to resolve this.

Replies are listed 'Best First'.
Re: Error with DBD::CSV
by syphilis (Archbishop) on Jul 21, 2010 at 09:30 UTC
    The line of code producing the error is (in open_file):
    $array = $attrs->{csv_csv_in}->getline ($tbl->{fh}) or croak "Missing first row";
    The error is that $attrs->{csv_csv_in} is undef.
    As you can see, from a few lines up, $attrs->{csv_csv_in} is simply a copy of $meta->{csv_in} (which must therefore also be undef).

    Beyond that, I can't help much. There's also this comment in CSV.pm, which may be of assistance in working out how the error has come to be:
    # open_table (0 is used up to and including DBI-1.1611 # Later versions use open_file (see DBD::CSV::Table)
    And you can see that the $DBD::File::VERSION is significant.

    Cheers,
    Rob
Re: Error with DBD::CSV
by rehsack (Sexton) on Jul 21, 2010 at 14:17 UTC

    Hi,

    this typically happens when an invalid csv attribute is set. Could you please verify your attributes and give us the output of

    $verinfo = $dbh->csv_version(); print "$verinfo\n"

    This works with DBD::CSV 0.30 and DBI 1.612 - what is highly recommended to be used when asking for support ;)

Re: Error with DBD::CSV
by mertserger (Curate) on Jul 21, 2010 at 09:31 UTC
    Digger

    I have sometimes had a similar perl error mesage when running some scripts which read XML files and parse them. The problem is quite likely to be in your data or more specifically in the fact the data isn't matching what the script is expecting to handle.

    I usually found that my script was trying to use a variable which had not been set a value. I would suggest finding what line 427 of CSV.pm is trying to do and see why you would have an undefined variable.

Re: Error with DBD::CSV
by Anonymous Monk on Jul 21, 2010 at 09:36 UTC
    Try increasing the DBI trace level
Re: Error with DBD::CSV
by Tux (Canon) on Aug 11, 2010 at 06:44 UTC

    I do not see any code, so I cannot tell how you created the database connection. The use of csv_auto_diag, which is also automatically set when using the autodie module, might help you.

    $ perl -MDBI -wle'DBI->connect("dbi:CSV:csv_auto_diag=1")->prepare("se +lect * from non_exist")->execute' DBD::CSV::st execute failed: Execution ERROR: Cannot open /home/merijn/non_exist: No such file or d +irectory (2) at /pro/lib/perl5/site_perl/5.10.1/x86_64-linux/DBD/File +.pm line 684 . [for Statement "select * from non_exist"] at -e line 1. $ perl -MDBI -wle'DBI->connect("dbi:CSV:csv_auto_diag=1")->prepare("se +lect * from empty_file")->execute' DBD::CSV::st execute failed: Execution ERROR: Missing first row at /pro/lib/perl5/site_perl/5.10.1/ +x86_64-linux/DBD/File.pm line 684 . [for Statement "select * from bin"] at -e line 1. $

    The second will also occur when the table cannot be opened as a file, e.g. when it is a folder or when the first line contains a (serious) error. If the header line was fine, errors in the data lines will now be printed immediately:

    $ perl -MDBI -wle'DBI->connect("dbi:CSV:csv_auto_diag=1")->prepare("se +lect * from bad")->execute' DBD::CSV::st execute failed: Error 2034 while reading file /home/merij +n/bad: EIF - Loose unescaped quote at /pro/lib/perl5/site_perl/5.10.1 +/SQL/Statement.pm line 1032 [for Statement "select * from bad"] at -e line 1. $

    I'll have a look if I can make the error reporting from the middle one (cannot open, empty file or bad header) a bit better.


    Enjoy, Have FUN! H.Merijn