Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Bad Text::CSV_XS parameter

by pcouderc (Monk)
on Apr 24, 2020 at 12:30 UTC ( [id://11116012]=perlquestion: print w/replies, xml ) Need Help??

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

What do I do wrong ?

... open my $fh, "<:encoding(utf8)", "ddd.CSV" ; my $csvfile=Text::CSV_XS->new (); until (eof $fh) { if($csvfile->parse(<$fh>)) { my @resu=$csvfile->fields(); print STDERR $resu[0],$resu[1]; } else { my $err = $csvfile->error_diag(); print STDERR "Erreur : $err\n"; } }

ddd.CSV :

"01012019","1816"

my unexpected resulted (unexpected from me...) :

Erreur : EIF - Loose unescaped quote

Thank you, o confinated monks !

Replies are listed 'Best First'.
Re: Bad Text::CSV_XS parameter
by haukex (Archbishop) on Apr 24, 2020 at 13:15 UTC

    It sounds like your input file isn't what you think it is or what you showed here; try hexdump -C ddd.CSV or od -tx1c ddd.CSV. Also, don't use the ->parse method to read a file, use $csv->getline($fh).

      My file is:
      hexdump -C ddd.CSV 00000000 ef bb bf 22 30 31 30 31 32 30 31 39 22 2c 22 31 |..."01012 +019","1| 00000010 38 31 36 22 0a 0a 0a |816"...| 00000017

        If you have a BOM you have to deal with it: BOM

Re: Bad Text::CSV_XS parameter
by afoken (Chancellor) on Apr 24, 2020 at 18:28 UTC
Re: Bad Text::CSV_XS parameter
by hippo (Bishop) on Apr 24, 2020 at 12:49 UTC

    I am unable to reproduce your findings with version 1.17 of Text::CSV_XS:

    $ cat ddd.CSV "01012019","1816" $ cat 11116012.pl use strict; use warnings; use Text::CSV_XS; open my $fh, "<:encoding(utf8)", "ddd.CSV" ; my $csvfile=Text::CSV_XS->new (); until (eof $fh) { if($csvfile->parse(<$fh>)) { my @resu=$csvfile->fields(); print STDERR $resu[0],$resu[1]; } else { my $err = $csvfile->error_diag(); print STDERR "Erreur : $err\n"; } } $ perl 11116012.pl 010120191816$
      how strange !!!!!!

      I am using debian, it is :

      $VERSION = "1.38";
Re: Bad Text::CSV_XS parameter
by marto (Cardinal) on Apr 24, 2020 at 12:59 UTC

    As posted I can't replicate your problem, only if I mess around with the input file.

    "01012019",\"1816"

    Is what you posted actually recreating the error for you? allow_loose_escapes.

      With allow_loose_escapes => 1, I get the same error message...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 00:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found