{
    "mode": "perldoc",
    "parameter": "Tie::Scalar",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Tie%3A%3AScalar/json",
    "generated": "2026-05-30T06:12:42Z",
    "synopsis": "package NewScalar;\nrequire Tie::Scalar;\n@ISA = qw(Tie::Scalar);\nsub FETCH { ... }           # Provide a needed method\nsub TIESCALAR { ... }       # Overrides inherited method\npackage NewStdScalar;\nrequire Tie::Scalar;\n@ISA = qw(Tie::StdScalar);\n# All methods provided by default, so define\n# only what needs be overridden\nsub FETCH { ... }\npackage main;\ntie $newscalar, 'NewScalar';\ntie $newstdscalar, 'NewStdScalar';",
    "sections": {
        "NAME": {
            "content": "Tie::Scalar, Tie::StdScalar - base class definitions for tied scalars\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "package NewScalar;\nrequire Tie::Scalar;\n\n@ISA = qw(Tie::Scalar);\n\nsub FETCH { ... }           # Provide a needed method\nsub TIESCALAR { ... }       # Overrides inherited method\n\n\npackage NewStdScalar;\nrequire Tie::Scalar;\n\n@ISA = qw(Tie::StdScalar);\n\n# All methods provided by default, so define\n# only what needs be overridden\nsub FETCH { ... }\n\n\npackage main;\n\ntie $newscalar, 'NewScalar';\ntie $newstdscalar, 'NewStdScalar';\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module provides some skeletal methods for scalar-tying classes. See\nperltie for a list of the functions required in tying a scalar to a\npackage. The basic Tie::Scalar package provides a \"new\" method, as well\nas methods \"TIESCALAR\", \"FETCH\" and \"STORE\". The Tie::StdScalar package\nprovides all the methods specified in perltie. It inherits from\nTie::Scalar and causes scalars tied to it to behave exactly like the\nbuilt-in scalars, allowing for selective overloading of methods. The\n\"new\" method is provided as a means of grandfathering, for classes that\nforget to provide their own \"TIESCALAR\" method.\n\nFor developers wishing to write their own tied-scalar classes, the\nmethods are summarized below. The perltie section not only documents\nthese, but has sample code as well:\n\nTIESCALAR classname, LIST\nThe method invoked by the command \"tie $scalar, classname\".\nAssociates a new scalar instance with the specified class. \"LIST\"\nwould represent additional arguments (along the lines of AnyDBMFile\nand compatriots) needed to complete the association.\n\nFETCH this\nRetrieve the value of the tied scalar referenced by *this*.\n\nSTORE this, value\nStore data *value* in the tied scalar referenced by *this*.\n\nDESTROY this\nFree the storage associated with the tied scalar referenced by\n*this*. This is rarely needed, as Perl manages its memory quite\nwell. But the option exists, should a class wish to perform specific\nactions upon the destruction of an instance.\n",
            "subsections": [
                {
                    "name": "Tie::Scalar vs Tie::StdScalar",
                    "content": "\"Tie::Scalar\" provides all the necessary methods, but one should realize\nthey do not do anything useful. Calling \"Tie::Scalar::FETCH\" or\n\"Tie::Scalar::STORE\" results in a (trappable) croak. And if you inherit\nfrom \"Tie::Scalar\", you *must* provide either a \"new\" or a \"TIESCALAR\"\nmethod.\n\nIf you are looking for a class that does everything for you that you\ndon't define yourself, use the \"Tie::StdScalar\" class, not the\n\"Tie::Scalar\" one.\n"
                }
            ]
        },
        "MORE INFORMATION": {
            "content": "The perltie section uses a good example of tying scalars by associating\nprocess IDs with priority.\n",
            "subsections": []
        }
    },
    "summary": "Tie::Scalar, Tie::StdScalar - base class definitions for tied scalars",
    "flags": [],
    "examples": [],
    "see_also": []
}