{
    "mode": "perldoc",
    "parameter": "Tie::Scalar",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Tie%3A%3AScalar/json",
    "generated": "2026-06-13T22:13:38Z",
    "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 perltie for a list of\nthe functions required in tying a scalar to a package. The basic Tie::Scalar package provides a\n\"new\" method, as well as methods \"TIESCALAR\", \"FETCH\" and \"STORE\". The Tie::StdScalar package\nprovides all the methods specified in perltie. It inherits from Tie::Scalar and causes scalars\ntied to it to behave exactly like the built-in scalars, allowing for selective overloading of\nmethods. The \"new\" method is provided as a means of grandfathering, for classes that forget to\nprovide their own \"TIESCALAR\" method.\n\nFor developers wishing to write their own tied-scalar classes, the methods are summarized below.\nThe perltie section not only documents these, but has sample code as well:\n\nTIESCALAR classname, LIST\nThe method invoked by the command \"tie $scalar, classname\". Associates a new scalar instance\nwith the specified class. \"LIST\" would represent additional arguments (along the lines of\nAnyDBMFile and 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 *this*. This is rarely\nneeded, as Perl manages its memory quite well. But the option exists, should a class wish to\nperform specific actions 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 they do not do anything\nuseful. Calling \"Tie::Scalar::FETCH\" or \"Tie::Scalar::STORE\" results in a (trappable) croak. And\nif you inherit from \"Tie::Scalar\", you *must* provide either a \"new\" or a \"TIESCALAR\" method.\n\nIf you are looking for a class that does everything for you that you don't define yourself, use\nthe \"Tie::StdScalar\" class, not the \"Tie::Scalar\" one.\n"
                }
            ]
        },
        "MORE INFORMATION": {
            "content": "The perltie section uses a good example of tying scalars by associating process IDs with\npriority.\n",
            "subsections": []
        }
    },
    "summary": "Tie::Scalar, Tie::StdScalar - base class definitions for tied scalars",
    "flags": [],
    "examples": [],
    "see_also": []
}