Encoding::HandleUtf8 - Fix the encoding for Perl value store (input) and general output (output) to a console or the web.
version 0.004
use Encoding::HandleUtf8 qw( fix_encoding fix_encoding_return ); ######################################################################## # Simple usage - CAUTION: clones the object. printf "%s\n", fix_encoding_return 'input', 'Here are some German umlauts: äÄüÜöÖßẞ'; ######################################################################## # Working with strings. my $string = 'Here are some German umlauts: äÄüÜöÖßẞ'; # Fix the encoding of a input string to handle them safe within Perl. fix_encoding 'input', $string; # Fix the encoding of a Perl variable for output. fix_encoding 'output', $string; print "$string\n"; ######################################################################## # Working with hashes. my %hash = ( a => 'äÄ', u => 'üÜ', o => 'öÖ', ss => 'ßẞ' ); # Fix the encoding of a hash to handle them safe within Perl. fix_encoding 'input', %hash; # Fix the encoding of a Perl hash for output. fix_encoding 'output', %hash; print "$_: $hash{$_}\n" for( keys %hash ); ######################################################################## # Working with hash references. my $hash = { a => 'äÄ', u => 'üÜ', o => 'öÖ', ss => 'ßẞ' }; # Fix the encoding of a hash reference to handle them safe within Perl. fix_encoding 'input', $hash; # Fix the encoding of a Perl hash reference for output. fix_encoding 'output', %hash; print "$_: $hash->{$_}\n" for( keys %{ $hash } ); ######################################################################## # Working with arrays. my @array = ( 'äÄ', 'üÜ', 'öÖ', 'ßẞ' ); # Fix the encoding of an array to handle them safe within Perl. fix_encoding 'input', @array; # Fix the encoding of a Perl array for output. fix_encoding 'output', @array; print "$_: $hash{$_}\n" for( @array ); ######################################################################## # Working with array references. my $array = [ 'äÄ', 'üÜ', 'öÖ', 'ßẞ' ]; # Fix the encoding of an array reference to handle them safe within Perl. fix_encoding 'input', $array; # Fix the encoding of a Perl array reference for output. fix_encoding 'output', @array; print "$_: $hash{$_}\n" for( @{ $array } );
Fix the encoding for Perl value store (input) and general output (output) to e.g. a console or the web.
Takes an direction and a object and fixes the encoding.
$direction
The direction in which the object should be fixed. Either input to work safely with inputs (convert to Unicode) or output to output (convert to UTF-8) them to e.g. a console or the web.
input
output
$obj
The actual object which should be fixed. Can either be a SCALAR, HASH or ARRAY (including but not mandentory: references).
SCALAR
HASH
ARRAY
$skip_latin
Skips Encoding::FixLatin's fix_latin call on scalars when $skip_latin is set to a true value.
Does and takes exactly the same as "fix_encoding" but instead touching the original supplied object it will clone it an return the new encoded object.
Encoding::HandleUtf8 warns about references it does not know. You can turn off this warnings by adding the reference name to the @IGNORE_LIST array.
@IGNORE_LIST
push @Encoding::HandleUtf8::IGNORE_LIST, 'JSON::Boolean';
By default the following references will be ignored (no warnings):
BURNERSK <burnersk@cpan.org>
This software is Copyright (c) 2014 by BURNERSK <burnersk@cpan.org>.
This is free software, licensed under:
The MIT (X11) License
To install Encoding::HandleUtf8, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Encoding::HandleUtf8
CPAN shell
perl -MCPAN -e shell install Encoding::HandleUtf8
For more information on module installation, please visit the detailed CPAN module installation guide.