in reply to Concerning Text::CSV_XS getline in while loop

This is one of the reasons I am proposing the new interface :-). Until then, put this at the top of the loop:

last unless @$cols_aref;

getline() returns an empty arrayref when it runs out of lines in the file so you need to check for an arrayref with no elements.

  • Comment on Re: Concerning Text::CSV_XS getline in while loop

Replies are listed 'Best First'.
Re^2: Concerning Text::CSV_XS getline in while loop
by freddo411 (Chaplain) on Dec 21, 2004 at 22:45 UTC
    getline() returns an empty arrayref when it runs out of lines in the file so you need to check for an arrayref with no elements.
    Makes sense. Oh, and thanks for the pointing getline() out to me.

    -------------------------------------
    Nothing is too wonderful to be true
    -- Michael Faraday

Re^2: Concerning Text::CSV_XS getline in while loop
by Anonymous Monk on Feb 27, 2010 at 16:38 UTC
    Hi, I am having a simular problem, but the EOF is found if a non-ASCII character is found in the input string, like a German U or character of the same kind. Depending on the file it happens at the offending line. The input file has been produced by EXCEL and making a CSV-file from it on a Windows computer, while the PERL-script is running on a Linux machine. Kind regards, Bert Mengerink SPOORHOBBY

      My bet would be you forgot to read the documentation, and did not pass binary => 1 in the constructor:

      my $csv = Text::CSV_XS->new ({ binary => 1, auto_diag => 1 });

      Enjoy, Have FUN! H.Merijn