Encode::Simple - Encode and decode text, simply
use Encode::Simple qw(encode encode_lax encode_utf8 decode decode_lax decode_utf8); my $bytes = encode 'Shift_JIS', $characters; my $bytes = encode_lax 'ASCII', $characters; my $bytes = encode_utf8 $characters; my $characters = decode 'cp1252', $bytes; my $characters = decode_lax 'UTF-8', $bytes; my $characters = decode_utf8 $bytes;
This module is a simple wrapper around Encode that presents "encode" and "decode" functions with straightforward behavior and error handling. See Encode::Supported for a list of supported encodings.
All functions are exported by name, as well as via the tags :all, :strict, :lax, and :utf8. By default, "encode", "encode_utf8", "decode", and "decode_utf8" are exported as in Encode.
:all
:strict
:lax
:utf8
my $bytes = encode $encoding, $characters;
Encodes the input string of characters into a byte string using $encoding. Throws an exception if the input string contains characters that are not valid or possible to represent in $encoding.
$encoding
my $bytes = encode_lax $encoding, $characters;
Encodes the input string of characters into a byte string using $encoding, encoding any invalid characters as a substitution character (the substitution character used depends on the encoding). Note that some encoders do not respect this option and may throw an exception anyway, this notably includes Encode::Unicode (but not UTF-8).
my $bytes = encode_utf8 $characters;
Since version 1.000.
Encodes the input string of characters into a UTF-8 byte string. Throws an exception if the input string contains characters that are not valid or possible to represent in UTF-8.
This function will use the more consistent and efficient "encode_utf8" in Unicode::UTF8 if installed, and is otherwise equivalent to "encode" with an encoding of UTF-8. It is not equivalent to "encode_utf8" in Encode, which should be avoided.
UTF-8
my $bytes = encode_utf8_lax $characters;
Encodes the input string of characters into a UTF-8 byte string, encoding any invalid characters as the Unicode replacement character U+FFFD, represented in UTF-8 as the three bytes 0xEFBFBD.
U+FFFD
0xEFBFBD
This function will use the more consistent and efficient "encode_utf8" in Unicode::UTF8 if installed, and is otherwise equivalent to "encode_lax" with an encoding of UTF-8. It is not equivalent to "encode_utf8" in Encode, which should be avoided.
my $characters = decode $encoding, $bytes;
Decodes the input byte string into a string of characters using $encoding. Throws an exception if the input bytes are not valid for $encoding.
my $characters = decode_lax $encoding, $bytes;
Decodes the input byte string into a string of characters using $encoding, decoding any malformed bytes to the Unicode replacement character (U+FFFD). Note that some encoders do not respect this option and may throw an exception anyway, this notably includes Encode::Unicode (but not UTF-8).
my $characters = decode_utf8 $bytes;
Decodes the input UTF-8 byte string into a string of characters. Throws an exception if the input bytes are not valid for UTF-8.
This function will use the more consistent and efficient "decode_utf8" in Unicode::UTF8 if installed, and is otherwise equivalent to "decode" with an encoding of UTF-8. It is not equivalent to "decode_utf8" in Encode, which should be avoided.
my $characters = decode_utf8_lax $bytes;
Decodes the input UTF-8 byte string into a string of characters, decoding any malformed bytes to the Unicode replacement character U+FFFD.
This function will use the more consistent and efficient "decode_utf8" in Unicode::UTF8 if installed, and is otherwise equivalent to "decode_lax" with an encoding of UTF-8. It is not equivalent to "decode_utf8" in Encode, which should be avoided.
Report any issues on the public bugtracker.
Dan Book <dbook@cpan.org>
This software is Copyright (c) 2018 by Dan Book.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
Unicode::UTF8
To install Encode::Simple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Encode::Simple
CPAN shell
perl -MCPAN -e shell install Encode::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.