Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^11: Text::CSV encoding parse()

by Tux (Abbot)
on Aug 21, 2019 at 06:48 UTC ( #11104764=note: print w/replies, xml ) Need Help??

in reply to Re^10: Text::CSV encoding parse()
in thread Text::CSV encoding parse()

So here it gets interesting. Is it possible to get us that list of url's online somewhere so I/we could test on them?

If not, would it be possible to install Data::Peek and show me/us the output of

foreach my $row (@sorted_urls) { DPeek ($row); $csv->parse ($row); my @csv = $csv->fields; #using Text::CSV my @row = split m/\|/ => $row; #using split on same $row DPeek "CSV: $csv[0]"; DPeek "SPLIT: $row[0]"; }

And I also have no idea what $q->p () has as influence on the output and I also guess that %q->p is a typo.

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^12: Text::CSV encoding parse()
by slugger415 (Monk) on Aug 21, 2019 at 17:56 UTC

    I can't really give you the whole shebang but here are a couple of URLs, including the first one which has the spanish characters.¿Cuales son las +partes de una cadena de conexión??scope=SSGU8G_12.1.0| +_jdbc_011.htm|0|1|1|0 +8G_12.1.0||1|1|1|1


      The problem with you pasting the data here inside the code tags, does not reflect the binary compatibility of your actual data.

      If I download this snippet, the code works fine:

      $ cat test.csv;Cuales s +on las partes de una cadena de conexi&#65533;n??scope=SSGU8G_12.1.0|h +ttps:// +dbc_pg.doc/ids_jdbc_011.htm|0|1|1|0 +8G_12.1.0||1|1|1|1 $ perl -CEO -MData::Peek -MText::CSV_XS -wE'my$c=Text::CSV_XS->new({se +p_char=>"|",auto_diag=>1,binary=>1});while(<>){$c->parse($_);DPeek fo +r$c->fields}' test.csv PV("\277Cuales s +on las partes de una cadena de conexi\363n??scope=SSGU8G_12.1"...\0) PV(" +bm.jdbc_pg.doc/ids_jdbc_011.htm"\0) PV("0"\0) PV("1"\0) PV("1"\0) PV("0"\0) PV(" +SSGU8G_12.1.0"\0) PV(" +sec.doc/ids_lb_002.htm"\0) PV("1"\0) PV("1"\0) PV("1"\0) PV("1"\0)

      The *output* is, as you could see, iso-8859-1 (latin1) instead of your expected utf-8, because the source data is iso-8859-1 (or a variety thereof) and does not require an upgrade to utf-8.

      You can however make the data utf-8 by decoding your source data:

      $ perl -CEO -MEncode=decode -MData::Peek -MText::CSV_XS -wE'my$c=Text: +:CSV_XS->new({sep_char=>"|",auto_diag=>1,binary=>1});while(<>){$c->pa +rse(decode("utf-8",$_));DPeek for$c->fields}' test.csv PV("\357\277\275 +Cuales son las partes de una cadena de conexi\357\277\275n??s"...\0) +[UTF8 "\x{fffd} +Cuales son las partes de una cadena de conexi\x{fffd}n??scope=SSGU8G_ +12.1.0"] PV(" +bm.jdbc_pg.doc/ids_jdbc_011.htm"\0) PV("0"\0) PV("1"\0) PV("1"\0) PV("0"\0) PV(" +SSGU8G_12.1.0"\0) PV(" +sec.doc/ids_lb_002.htm"\0) PV("1"\0) PV("1"\0) PV("1"\0) PV("1"\0)

      Note that Text::CSV_XS *only* decodes to utf-8 if it needs to or is explicitly told to: it needs to be able to deal with pure binary data.

      Enjoy, Have FUN! H.Merijn

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11104764]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2021-02-27 04:36 GMT
Find Nodes?
    Voting Booth?

    No recent polls found