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.