{
    "mode": "perldoc",
    "parameter": "Text::Iconv",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Text%3A%3AIconv/json",
    "generated": "2026-06-09T11:33:54Z",
    "synopsis": "use Text::Iconv;\n$converter = Text::Iconv->new(\"fromcode\", \"tocode\");\n$converted = $converter->convert(\"Text to convert\");",
    "sections": {
        "NAME": {
            "content": "Text::Iconv - Perl interface to iconv() codeset conversion function\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Text::Iconv;\n$converter = Text::Iconv->new(\"fromcode\", \"tocode\");\n$converted = $converter->convert(\"Text to convert\");\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The Text::Iconv module provides a Perl interface to the iconv() function as defined by the\nSingle UNIX Specification.\n\nThe convert() method converts the encoding of characters in the input string from the *fromcode*\ncodeset to the *tocode* codeset, and returns the result.\n\nSettings of *fromcode* and *tocode* and their permitted combinations are\nimplementation-dependent. Valid values are specified in the system documentation; the iconv(1)\nutility should also provide a -l option that lists all supported codesets.\n",
            "subsections": [
                {
                    "name": "Utility methods",
                    "content": "Text::Iconv objects also provide the following methods:\n"
                },
                {
                    "name": "retval",
                    "content": "according to the Single UNIX Specification, this value indicates \"the number of non-identical\nconversions performed.\" Note, however, that iconv implementations vary widely in the\ninterpretation of this specification.\n\nThis method can be called after calling convert(), e.g.:\n\n$result = $converter->convert(\"lorem ipsum dolor sit amet\");\n$retval = $converter->retval;\n\nWhen called before the first call to convert(), or if an error occured during the conversion,"
                },
                {
                    "name": "retval",
                    "content": ""
                },
                {
                    "name": "get_attr",
                    "content": "The getattr() method allows you to query various attributes which influence the behavior of"
                },
                {
                    "name": "convert",
                    "content": "*discardilseq*, e.g.:\n\n$state = $converter->getattr(\"transliterate\");\n\nSee iconvctl(3) for details. To ensure portability to other iconv implementations you should\nfirst check for the availability of this method using eval {}, e.g.:\n\neval { $conv->getattr(\"trivialp\") };\nif ($@)\n{\n# getattr() is not available\n}\nelse\n{\n# getattr() is available\n}\n\nThis method should be considered experimental.\n"
                },
                {
                    "name": "set_attr",
                    "content": "The setattr() method allows you to set various attributes which influence the behavior of"
                },
                {
                    "name": "convert",
                    "content": "$state = $converter->setattr(\"transliterate\");\n\nSee iconvctl(3) for details. To ensure portability to other iconv implementations you should\nfirst check for the availability of this method using eval {}, cf. the description of setattr()\nabove.\n\nThis method should be considered experimental.\n"
                }
            ]
        },
        "ERRORS": {
            "content": "If the conversion can't be initialized an exception is raised (using croak()).\n",
            "subsections": [
                {
                    "name": "Handling of conversion errors",
                    "content": "*Text::Iconv* provides a class attribute raiseerror and a corresponding class method for\nsetting and getting its value. The handling of errors during conversion depends on the setting\nof this attribute. If raiseerror is set to a true value, an exception is raised; otherwise, the"
                },
                {
                    "name": "convert",
                    "content": "Text::Iconv->raiseerror(1);     # Conversion errors raise exceptions\nText::Iconv->raiseerror(0);     # Conversion errors return undef\n$a = Text::Iconv->raiseerror(); # Get current setting\n"
                },
                {
                    "name": "Per-object handling of conversion errors",
                    "content": "As an experimental feature, *Text::Iconv* also provides an instance attribute raiseerror and a\ncorresponding method for setting and getting its value. If raiseerror is undef, the class-wide\nsettings apply. If raiseerror is 1 or 0 (true or false), the object settings override the\nclass-wide settings.\n\nConsult iconv(3) for details on errors that might occur.\n"
                },
                {
                    "name": "Conversion of undef",
                    "content": "Converting undef, e.g.,\n\n$converted = $converter->convert(undef);\n\nalways returns undef. This is not considered an error.\n"
                }
            ]
        },
        "NOTES": {
            "content": "The supported codesets, their names, the supported conversions, and the quality of the\nconversions are all system-dependent.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Michael Piotrowski <mxp@dynalabs.de>\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "",
            "subsections": [
                {
                    "name": "iconv",
                    "content": ""
                }
            ]
        }
    },
    "summary": "Text::Iconv - Perl interface to iconv() codeset conversion function",
    "flags": [],
    "examples": [],
    "see_also": []
}