The Text::Iconv module provides a Perl interface to the iconv() function as defined by the Single UNIX
Specification.
The convert() method converts the encoding of characters in the input string from the fromcode codeset to
the tocode codeset, and returns the result.
Settings of fromcode and tocode and their permitted combinations are implementation-dependent. Valid
values are specified in the system documentation; the iconv(1) utility should also provide a -l option
that lists all supported codesets.
UtilitymethodsText::Iconv objects also provide the following methods:
retval() returns the return value of the underlying iconv() function for the last conversion; according
to the Single UNIX Specification, this value indicates "the number of non-identical conversions
performed." Note, however, that iconv implementations vary widely in the interpretation of this
specification.
This method can be called after calling convert(), e.g.:
$result = $converter->convert("lorem ipsum dolor sit amet");
$retval = $converter->retval;
When called before the first call to convert(), or if an error occured during the conversion, retval()
returns undef.
get_attr(): This method is only available with GNU libiconv, otherwise it throws an exception. The
get_attr() method allows you to query various attributes which influence the behavior of convert(). The
currently supported attributes are trivialp, transliterate, and discard_ilseq, e.g.:
$state = $converter->get_attr("transliterate");
See iconvctl(3) for details. To ensure portability to other iconv implementations you should first check
for the availability of this method using eval{}, e.g.:
eval { $conv->get_attr("trivialp") };
if ($@)
{
# get_attr() is not available
}
else
{
# get_attr() is available
}
This method should be considered experimental.
set_attr(): This method is only available with GNU libiconv, otherwise it throws an exception. The
set_attr() method allows you to set various attributes which influence the behavior of convert(). The
currently supported attributes are transliterate and discard_ilseq, e.g.:
$state = $converter->set_attr("transliterate");
See iconvctl(3) for details. To ensure portability to other iconv implementations you should first check
for the availability of this method using eval{}, cf. the description of set_attr() above.
This method should be considered experimental.