swilting has asked for the wisdom of the Perl Monks concerning the following question:
how to best way to encode all of data in input
like this
#!/usr/bin/perl use Encode qw(all); my $ENC_ASCII = 'ASCII'; # When all other defaults are exhausted, use UTF-8 my $result = undef; eval{ $result = Encode::encode_utf8($text);1; }; if($@){ } if($result){ return $result; } # Something is seriously wrong if we get to here return encode($ENC_ASCII, $text, undef);
like that
# IO layer: $handle now decodes all strings upon reading open my $handle, '<:encoding(UTF-8)', $file;
or
binmode $handle, ':encoding(UTF-8)';
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: how to use Encode qw(all)
by almut (Canon) on Apr 05, 2010 at 15:24 UTC | |
by swilting (Beadle) on Apr 05, 2010 at 15:44 UTC |
Back to
Seekers of Perl Wisdom