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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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

In reply to Re^13: Text::CSV encoding parse() by Tux
in thread Text::CSV encoding parse() by slugger415

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (4)
    As of 2021-04-22 20:19 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found