{
    "mode": "perldoc",
    "parameter": "builtin",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/builtin/json",
    "generated": "2026-10-09T13:05:08Z",
    "synopsis": "use builtin qw(\ntrue false isbool\nweaken unweaken isweak\nblessed refaddr reftype\ncreatedasstring createdasnumber\nceil floor\nindexed\ntrim\nistainted\nexportlexically\n);",
    "sections": {
        "NAME": {
            "content": "builtin - Perl pragma to import built-in utility functions\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use builtin qw(\ntrue false isbool\nweaken unweaken isweak\nblessed refaddr reftype\ncreatedasstring createdasnumber\nceil floor\nindexed\ntrim\nistainted\nexportlexically\n);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Perl provides several utility functions in the \"builtin\" package. These are plain functions, and\nlook and behave just like regular user-defined functions do. They do not provide new syntax or\nrequire special parsing. These functions are always present in the interpreter and can be called\nat any time by their fully-qualified names. By default they are not available as short names,\nbut can be requested for convenience.\n\nIndividual named functions can be imported by listing them as import parameters on the \"use\"\nstatement for this pragma.\n\nThe overall \"builtin\" mechanism, as well as every individual function it provides, are currently\nexperimental.\n\nWarning: At present, the entire \"builtin\" namespace is experimental. Calling functions in it\nwill trigger warnings of the \"experimental::builtin\" category.\n",
            "subsections": [
                {
                    "name": "Lexical Import",
                    "content": "This pragma module creates *lexical* aliases in the currently-compiling scope to these builtin\nfunctions. This is similar to the lexical effect of other pragmas such as strict and feature.\n\nsub classify\n{\nmy $val = shift;\n\nuse builtin 'isbool';\nreturn isbool($val) ? \"boolean\" : \"not a boolean\";\n}\n\n# the isbool() function is no longer visible here\n# but may still be called by builtin::isbool()\n\nBecause these functions are imported lexically, rather than by package symbols, the user does\nnot need to take any special measures to ensure they don't accidentally appear as object methods\nfrom a class.\n\npackage An::Object::Class {\nuse builtin 'true', 'false';\n...\n}\n\n# does not appear as a method\nAn::Object::Class->true;\n\n# Can't locate object method \"true\" via package \"An::Object::Class\"\n#   at ...\n"
                }
            ]
        },
        "FUNCTIONS": {
            "content": "true\n$val = true;\n\nReturns the boolean truth value. While any scalar value can be tested for truth and most\ndefined, non-empty and non-zero values are considered \"true\" by perl, this one is special in\nthat \"isbool\" considers it to be a distinguished boolean value.\n\nThis gives an equivalent value to expressions like \"!!1\" or \"!0\".\n\nfalse\n$val = false;\n\nReturns the boolean fiction value. While any non-true scalar value is considered \"false\" by\nperl, this one is special in that \"isbool\" considers it to be a distinguished boolean value.\n\nThis gives an equivalent value to expressions like \"!!0\" or \"!1\".\n\nisbool\n$bool = isbool($val);\n\nReturns true when given a distinguished boolean value, or false if not. A distinguished boolean\nvalue is the result of any boolean-returning builtin function (such as \"true\" or \"isbool\"\nitself), boolean-returning operator (such as the \"eq\" or \"==\" comparison tests or the \"!\"\nnegation operator), or any variable containing one of these results.\n\nThis function used to be named \"isbool\". A compatibility alias is provided currently but will be\nremoved in a later version.\n\nweaken\nweaken($ref);\n\nWeakens a reference. A weakened reference does not contribute to the reference count of its\nreferent. If only weakened references to a referent remain, it will be disposed of, and all\nremaining weak references to it will have their value set to \"undef\".\n\nunweaken\nunweaken($ref);\n\nStrengthens a reference, undoing the effects of a previous call to \"weaken\".\n\nisweak\n$bool = isweak($ref);\n\nReturns true when given a weakened reference, or false if not a reference or not weak.\n\nThis function used to be named \"isweak\". A compatibility alias is provided currently but will be\nremoved in a later version.\n\nblessed\n$str = blessed($ref);\n\nReturns the package name for an object reference, or \"undef\" for a non-reference or reference\nthat is not an object.\n\nrefaddr\n$num = refaddr($ref);\n\nReturns the memory address for a reference, or \"undef\" for a non-reference. This value is not\nlikely to be very useful for pure Perl code, but is handy as a means to test for referential\nidentity or uniqueness.\n\nreftype\n$str = reftype($ref);\n\nReturns the basic container type of the referent of a reference, or \"undef\" for a non-reference.\nThis is returned as a string in all-capitals, such as \"ARRAY\" for array references, or \"HASH\"\nfor hash references.\n\ncreatedasstring\n$bool = createdasstring($val);\n\nReturns a boolean representing if the argument value was originally created as a string. It will\nreturn true for any scalar expression whose most recent assignment or modification was of a\nstring-like nature - such as assignment from a string literal, or the result of a string\noperation such as concatenation or regexp. It will return false for references (including any\nobject), numbers, booleans and undef.\n\nIt is unlikely that you will want to use this for regular data validation within Perl, as it\nwill not return true for regular numbers that are still perfectly usable as strings, nor for any\nobject reference - especially objects that overload the stringification operator in an attempt\nto behave more like strings. For example\n\nmy $val = URI->new( \"https://metacpan.org/\" );\n\nif( createdasstring $val ) { ... }    # this will not execute\n\ncreatedasnumber\n$bool = createdasnumber($val);\n\nReturns a boolean representing if the argument value was originally created as a number. It will\nreturn true for any scalar expression whose most recent assignment or modification was of a\nnumerical nature - such as assignment from a number literal, or the result of a numerical\noperation such as addition. It will return false for references (including any object), strings,\nbooleans and undef.\n\nIt is unlikely that you will want to use this for regular data validation within Perl, as it\nwill not return true for regular strings of decimal digits that are still perfectly usable as\nnumbers, nor for any object reference - especially objects that overload the numification\noperator in an attempt to behave more like numbers. For example\n\nmy $val = Math::BigInt->new( 123 );\n\nif( createdasnumber $val ) { ... }    # this will not execute\n\nWhile most Perl code should operate on scalar values without needing to know their creation\nhistory, these two functions are intended to be used by data serialisation modules such as JSON\nencoders or similar situations, where language interoperability concerns require making a\ndistinction between values that are fundamentally stringlike versus numberlike in nature.\n\nceil\n$num = ceil($num);\n\nReturns the smallest integer value greater than or equal to the given numerical argument.\n\nfloor\n$num = floor($num);\n\nReturns the largest integer value less than or equal to the given numerical argument.\n\nindexed\n@ivpairs = indexed(@items)\n\nReturns an even-sized list of number/value pairs, where each pair is formed of a number giving\nan index in the original list followed by the value at that position in it. I.e. returns a list\ntwice the size of the original, being equal to\n\n(0, $items[0], 1, $items[1], 2, $items[2], ...)\n\nNote that unlike the core \"values\" function, this function returns copies of its original\narguments, not aliases to them. Any modifications of these copies are *not* reflected in\nmodifications to the original.\n\nmy @x = ...;\n$++ for indexed @x;  # The @x array remains unaffected\n\nThis function is primarily intended to be useful combined with multi-variable \"foreach\" loop\nsyntax; as\n\nforeach my ($index, $value) (indexed LIST) {\n...\n}\n\nIn scalar context this function returns the size of the list that it would otherwise have\nreturned, and provokes a warning in the \"scalar\" category.\n\ntrim\n$stripped = trim($string);\n\nReturns the input string with whitespace stripped from the beginning and end. trim() will remove\nthese characters:\n\n\" \", an ordinary space.\n\n\"\\t\", a tab.\n\n\"\\n\", a new line (line feed).\n\n\"\\r\", a carriage return.\n\nand all other Unicode characters that are flagged as whitespace. A complete list is in\n\"Whitespace\" in perlrecharclass.\n\n$var = \"  Hello world   \";            # \"Hello world\"\n$var = \"\\t\\t\\tHello world\";           # \"Hello world\"\n$var = \"Hello world\\n\";               # \"Hello world\"\n$var = \"\\x{2028}Hello world\\x{3000}\"; # \"Hello world\"\n\n\"trim\" is equivalent to:\n\n$str =~ s/\\A\\s+|\\s+\\z//urg;\n\nFor Perl versions where this feature is not available look at the String::Util module for a\ncomparable implementation.\n\nistainted\n$bool = istainted($var);\n\nReturns true when given a tainted variable.\n\nexportlexically\nexportlexically($name1, $ref1, $name2, $ref2, ...)\n\nExports new lexical names into the scope currently being compiled. Names given by the first of\neach pair of values will refer to the corresponding item whose reference is given by the second.\nTypes of item that are permitted are subroutines, and scalar, array, and hash variables. If the\nitem is a subroutine, the name may optionally be prefixed with the \"&\" sigil, but for\nconvenience it doesn't have to. For items that are variables the sigil is required, and must\nmatch the type of the variable.\n\nexportlexically func    => \\&func,\n'&func' => \\&func;  # same as above\n\nexportlexically '$scalar' => \\my $var;\n\n\n\n# The following are not permitted\nexportlexically '$var' => \\@arr;   # sigil does not match\nexportlexically name => \\$scalar;  # implied '&' sigil does not match\n\nexportlexically '*name' => \\*globref;  # globrefs are not supported\n\nThis must be called at compile time; which typically means during a \"BEGIN\" block. Usually this\nwould be used as part of an \"import\" method of a module, when invoked as part of a \"use ...\"\nstatement.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "perlop, perlfunc, Scalar::Util\n",
            "subsections": []
        }
    },
    "summary": "builtin - Perl pragma to import built-in utility functions",
    "flags": [],
    "examples": [],
    "see_also": []
}