{
    "content": [
        {
            "type": "text",
            "text": "# Scalar::Util (perldoc)\n\n## NAME\n\nScalar::Util - A selection of general-utility scalar subroutines\n\n## SYNOPSIS\n\nuse Scalar::Util qw(blessed dualvar isdual readonly refaddr reftype\ntainted weaken isweak isvstring lookslikenumber\nsetprototype);\n# and other useful utils appearing below\n\n## DESCRIPTION\n\n\"Scalar::Util\" contains a selection of subroutines that people have expressed would be nice to\nhave in the perl core, but the usage would not really be high enough to warrant the use of a\nkeyword, and the size would be so small that being individual extensions would be wasteful.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **FUNCTIONS FOR REFERENCES**\n- **OTHER FUNCTIONS**\n- **DIAGNOSTICS**\n- **KNOWN BUGS**\n- **SEE ALSO**\n- **COPYRIGHT**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Scalar::Util",
        "section": "",
        "mode": "perldoc",
        "summary": "Scalar::Util - A selection of general-utility scalar subroutines",
        "synopsis": "use Scalar::Util qw(blessed dualvar isdual readonly refaddr reftype\ntainted weaken isweak isvstring lookslikenumber\nsetprototype);\n# and other useful utils appearing below",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "FUNCTIONS FOR REFERENCES",
                "lines": 118,
                "subsections": []
            },
            {
                "name": "OTHER FUNCTIONS",
                "lines": 89,
                "subsections": []
            },
            {
                "name": "DIAGNOSTICS",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "KNOWN BUGS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 12,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Scalar::Util - A selection of general-utility scalar subroutines\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use Scalar::Util qw(blessed dualvar isdual readonly refaddr reftype\ntainted weaken isweak isvstring lookslikenumber\nsetprototype);\n# and other useful utils appearing below\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "\"Scalar::Util\" contains a selection of subroutines that people have expressed would be nice to\nhave in the perl core, but the usage would not really be high enough to warrant the use of a\nkeyword, and the size would be so small that being individual extensions would be wasteful.\n\nBy default \"Scalar::Util\" does not export any subroutines.\n",
                "subsections": []
            },
            "FUNCTIONS FOR REFERENCES": {
                "content": "The following functions all perform some useful activity on reference values.\n\nblessed\nmy $pkg = blessed( $ref );\n\nIf $ref is a blessed reference, the name of the package that it is blessed into is returned.\nOtherwise \"undef\" is returned.\n\n$scalar = \"foo\";\n$class  = blessed $scalar;           # undef\n\n$ref    = [];\n$class  = blessed $ref;              # undef\n\n$obj    = bless [], \"Foo\";\n$class  = blessed $obj;              # \"Foo\"\n\nTake care when using this function simply as a truth test (such as in \"if(blessed $ref)...\")\nbecause the package name \"0\" is defined yet false.\n\nrefaddr\nmy $addr = refaddr( $ref );\n\nIf $ref is reference, the internal memory address of the referenced value is returned as a plain\ninteger. Otherwise \"undef\" is returned.\n\n$addr = refaddr \"string\";           # undef\n$addr = refaddr \\$var;              # eg 12345678\n$addr = refaddr [];                 # eg 23456784\n\n$obj  = bless {}, \"Foo\";\n$addr = refaddr $obj;               # eg 88123488\n\nreftype\nmy $type = reftype( $ref );\n\nIf $ref is a reference, the basic Perl type of the variable referenced is returned as a plain\nstring (such as \"ARRAY\" or \"HASH\"). Otherwise \"undef\" is returned.\n\n$type = reftype \"string\";           # undef\n$type = reftype \\$var;              # SCALAR\n$type = reftype [];                 # ARRAY\n\n$obj  = bless {}, \"Foo\";\n$type = reftype $obj;               # HASH\n\nNote that for internal reasons, all precompiled regexps (\"qr/.../\") are blessed references; thus\n\"ref()\" returns the package name string \"Regexp\" on these but \"reftype()\" will return the\nunderlying C structure type of \"REGEXP\" in all capitals.\n\nweaken\nweaken( $ref );\n\nThe lvalue $ref will be turned into a weak reference. This means that it will not hold a\nreference count on the object it references. Also, when the reference count on that object\nreaches zero, the reference will be set to undef. This function mutates the lvalue passed as its\nargument and returns no value.\n\nThis is useful for keeping copies of references, but you don't want to prevent the object being\nDESTROY-ed at its usual time.\n\n{\nmy $var;\n$ref = \\$var;\nweaken($ref);                     # Make $ref a weak reference\n}\n# $ref is now undef\n\nNote that if you take a copy of a scalar with a weakened reference, the copy will be a strong\nreference.\n\nmy $var;\nmy $foo = \\$var;\nweaken($foo);                       # Make $foo a weak reference\nmy $bar = $foo;                     # $bar is now a strong reference\n\nThis may be less obvious in other situations, such as \"grep()\", for instance when grepping\nthrough a list of weakened references to objects that may have been destroyed already:\n\n@object = grep { defined } @object;\n\nThis will indeed remove all references to destroyed objects, but the remaining references to\nobjects will be strong, causing the remaining objects to never be destroyed because there is now\nalways a strong reference to them in the @object array.\n\nunweaken\nunweaken( $ref );\n\n*Since version 1.36.*\n\nThe lvalue \"REF\" will be turned from a weak reference back into a normal (strong) reference\nagain. This function mutates the lvalue passed as its argument and returns no value. This undoes\nthe action performed by \"weaken\".\n\nThis function is slightly neater and more convenient than the otherwise-equivalent code\n\nmy $tmp = $REF;\nundef $REF;\n$REF = $tmp;\n\n(because in particular, simply assigning a weak reference back to itself does not work to\nunweaken it; \"$REF = $REF\" does not work).\n\nisweak\nmy $weak = isweak( $ref );\n\nReturns true if $ref is a weak reference.\n\n$ref  = \\$foo;\n$weak = isweak($ref);               # false\nweaken($ref);\n$weak = isweak($ref);               # true\n\nNOTE: Copying a weak reference creates a normal, strong, reference.\n\n$copy = $ref;\n$weak = isweak($copy);              # false\n",
                "subsections": []
            },
            "OTHER FUNCTIONS": {
                "content": "dualvar\nmy $var = dualvar( $num, $string );\n\nReturns a scalar that has the value $num in a numeric context and the value $string in a string\ncontext.\n\n$foo = dualvar 10, \"Hello\";\n$num = $foo + 2;                    # 12\n$str = $foo . \" world\";             # Hello world\n\nisdual\nmy $dual = isdual( $var );\n\n*Since version 1.26.*\n\nIf $var is a scalar that has both numeric and string values, the result is true.\n\n$foo = dualvar 86, \"Nix\";\n$dual = isdual($foo);               # true\n\nNote that a scalar can be made to have both string and numeric content through standard\noperations:\n\n$foo = \"10\";\n$dual = isdual($foo);               # false\n$bar = $foo + 0;\n$dual = isdual($foo);               # true\n\nThe $! variable is commonly dual-valued, though it is also magical in other ways:\n\n$! = 1;\n$dual = isdual($!);                 # true\nprint(\"$!\\n\");                      # \"Operation not permitted\"\n\nCAUTION: This function is not as useful as it may seem. Dualvars are not a distinct concept in\nPerl, but a standard internal construct of all scalar values. Almost any value could be\nconsidered as a dualvar by this function through the course of normal operations.\n\nisvstring\nmy $vstring = isvstring( $var );\n\nIf $var is a scalar which was coded as a vstring, the result is true.\n\n$vs   = v49.46.48;\n$fmt  = isvstring($vs) ? \"%vd\" : \"%s\"; #true\nprintf($fmt,$vs);\n\nlookslikenumber\nmy $isnum = lookslikenumber( $var );\n\nReturns true if perl thinks $var is a number. See \"lookslikenumber\" in perlapi.\n\nopenhandle\nmy $fh = openhandle( $fh );\n\nReturns $fh itself, if $fh may be used as a filehandle and is open, or if it is a tied handle.\nOtherwise \"undef\" is returned.\n\n$fh = openhandle(*STDIN);           # \\*STDIN\n$fh = openhandle(\\*STDIN);          # \\*STDIN\n$fh = openhandle(*NOTOPEN);         # undef\n$fh = openhandle(\"scalar\");         # undef\n\nreadonly\nmy $ro = readonly( $var );\n\nReturns true if $var is readonly.\n\nsub foo { readonly($[0]) }\n\n$readonly = foo($bar);              # false\n$readonly = foo(0);                 # true\n\nsetprototype\nmy $code = setprototype( $code, $prototype );\n\nSets the prototype of the function given by the $code reference, or deletes it if $prototype is\n\"undef\". Returns the $code reference itself.\n\nsetprototype \\&foo, '$$';\n\ntainted\nmy $t = tainted( $var );\n\nReturn true if $var is tainted.\n\n$taint = tainted(\"constant\");       # false\n$taint = tainted($ENV{PWD});        # true if running under -T\n",
                "subsections": []
            },
            "DIAGNOSTICS": {
                "content": "Module use may give one of the following errors during import.\n\nVstrings are not implemented in this version of perl\nThe version of perl that you are using does not implement Vstrings, to use \"isvstring\" you\nwill need to use a newer release of perl.\n",
                "subsections": []
            },
            "KNOWN BUGS": {
                "content": "There is a bug in perl5.6.0 with UV's that are >= 1<<31. This will show up as tests 8 and 9 of\ndualvar.t failing\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "List::Util\n",
                "subsections": []
            },
            "COPYRIGHT": {
                "content": "Copyright (c) 1997-2007 Graham Barr <gbarr@pobox.com>. All rights reserved. This program is free\nsoftware; you can redistribute it and/or modify it under the same terms as Perl itself.\n\nAdditionally \"weaken\" and \"isweak\" which are\n\nCopyright (c) 1999 Tuomas J. Lukka <lukka@iki.fi>. All rights reserved. This program is free\nsoftware; you can redistribute it and/or modify it under the same terms as perl itself.\n\nCopyright (C) 2004, 2008 Matthijs van Duin. All rights reserved. Copyright (C) 2014 cPanel Inc.\nAll rights reserved. This program is free software; you can redistribute it and/or modify it\nunder the same terms as Perl itself.\n",
                "subsections": []
            }
        }
    }
}