Hi folks i've been trying to solve this issue for weeks with no success at all.
I'm getting a CSV file from a website. Its not encoded in UTF-8. Hence, when you save it, characters which are written in french are displayed wrongly. I.e. the accent formatting is lost.
I'm also getting an error:
Failed: Cannot decode string with wide characters at C:/Perl/lib/Encode.pm line
174.
Could someone kindly look into this code and let me know what i'm doing wrong?
Your help is much appreciated!
Here is where my function is getting called
my ($confn,$pegfn,$pirfn,$pittmfn) = map { "$conf::backup_dir/$_-$tim.
+csv" }
("consum", "peg", "pir", "pittm");
$mech->follow_link(url_regex=>qr/sitestat\.com.*pir.*export_csv/i);
$mech->save_content_binary($pirfn);
here is my save_content_binary method:
sub save_content_binary {
my $self = shift;
my $filename = shift;
open( my $fh, '>:utf8', $filename ) or $self->die( "Unable to crea
+te $filename: $!" );
binmode $fh;
decode("utf-8",$self->content);
print {$fh} $self->content or $self->die( "Unable to write to $fil
+ename: $!" );
close $fh or $self->die( "Unable to close $filename: $!" );
return;
}
i know i'm meant to use the encode or decode methods, but not sure which one or when.
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, details, 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, summary, 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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.