Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by slugger415 (Monk)
on Aug 16, 2019 at 18:35 UTC ( #11104578=note: print w/replies, xml ) Need Help??


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

Hello, thank you for the test code. Yes I see the same in the browser with your sample code. I've substituted my own string for yours and here's what I see now in the browser:

$VAR1 = "/search/\x{bf}Cuales son las partes de una cadena de conexi\x +{f3}n??scope=SSGU8G_12.1.0|/com.ibm.jdbc_pg.doc/ids_jdbc_011.htm|0|1| +1|0\n"; UTF-8 flag is on /search/¿Cuales son las partes de una cadena de conexión??scope=SSGU8G +_12.1.0|/com.ibm.jdbc_pg.doc/ids_jdbc_011.htm|0|1|1|0 After Text::CSV: /search/¿Cuales son las partes de una cadena de conex +ión??scope=SSGU8G_12.1.0 | /com.ibm.jdbc_pg.doc/ids_jdbc_011.htm

BTW I'm assigning $data by reading a stdout output file that is returned from the db via the tool I'm using for the SQL query.

my($data); open my $fh, "<:encoding(utf8)", $file || die("cannot open $file file\ +n"); while(<$fh>){ if($_ =~ /Cuales/){ $data = $_; print $_; } } close($fh);

I've also tried opening the file without the :encoding and get the same result.

open(R, "$resultsFile") || die("cannot open results file $resultsFile +for reading.\n");

Hope this is helpful.

Replies are listed 'Best First'.
Re^9: Text::CSV encoding parse()
by haukex (Chancellor) on Aug 17, 2019 at 06:47 UTC
    I've substituted my own string for yours and here's what I see now in the browser:
    $VAR1 = "/search/\x{bf}Cuales son las partes de una cadena de conexi\x{f3}n??scope=SSGU8G_12.1.0|/com.ibm.jdbc_pg.doc/ids_jdbc_011.htm|0|1|1|0\n";
    UTF-8 flag is on
    
    /search/¿Cuales son las partes de una cadena de conexión??scope=SSGU8G_12.1.0|/com.ibm.jdbc_pg.doc/ids_jdbc_011.htm|0|1|1|0
    
    After Text::CSV: /search/¿Cuales son las partes de una cadena de conexión??scope=SSGU8G_12.1.0 | /com.ibm.jdbc_pg.doc/ids_jdbc_011.htm
    

    \x{bf} or U+00BF is the inverted question mark and U+00F3 is “ó”, so AFAICT that looks correct, doesn't it?

    BTW I'm assigning $data by reading a stdout output file that is returned from the db via the tool I'm using for the SQL query.

    Ok, so do I understand correctly that you've tested the code you showed within the script I posted?

    (BTW, why not use DBI to connect directly to the database instead of going through a file?)

    I've also tried opening the file without the :encoding and get the same result.

    Well, if you've got the use open qw/:std :utf8/; that I suggested at the top of the script, that also sets utf8 as the default encoding layer. As long as you're not getting warnings such as "Malformed UTF-8 character: \xbf" or "utf8 "\xBF" does not map to Unicode" (check the web server's error logs and/or run the script from the command line), then it would seem your file is probably encoded as UTF-8, and it would seem that everything is correct...

    So are you still seeing the same problem as before, or is it working now?

      \x{bf} or U+00BF is the inverted question mark and U+00F3 is “ó”, so AFAICT that looks correct, doesn't it?

      Yes it looks correct in my browser.

      Ok, so do I understand correctly that you've tested the code you showed within the script I posted?

      Yes.

      (BTW, why not use DBI to connect directly to the database instead of going through a file?)

      Working on that! The tool I'm currently using doesn't allow it, so I'm running a system command to execute the query. Researching direct DBI access but there are access issues within my org...

      So are you still seeing the same problem as before, or is it working now?

      Sadly problem still exists, yes. To summarize:

      foreach my $row (@sorted_urls){ $csv->parse($row); my @els = $csv->fields; #using Text::CSV my(@splits) = split('\|',$row); #using split on same $row print $q->p($els[0]); #prints wrong print %q->p(splits[0]); #prints right }

      Honestly this is not worth wasting a lot of time on, though I really appreciate your help... thank you.

        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
        Sadly problem still exists, yes. To summarize:

        That's strange. Could you please show a complete example of the code that doesn't work, i.e. the full script along with its output? Also, to play it safe, try upgrading your installations of Text::CSV and Text::CSV_XS.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2019-09-21 19:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (273 votes). Check out past polls.

    Notices?