{
    "content": [
        {
            "type": "text",
            "text": "# IO::Scalar (perldoc)\n\n## NAME\n\nIO::Scalar - IO:: interface for reading/writing a scalar\n\n## SYNOPSIS\n\nPerform I/O on strings, using the basic OO interface...\nuse 5.005;\nuse IO::Scalar;\n$data = \"My message:\\n\";\n### Open a handle on a string, and append to it:\n$SH = new IO::Scalar \\$data;\n$SH->print(\"Hello\");\n$SH->print(\", world!\\nBye now!\\n\");\nprint \"The string is now: \", $data, \"\\n\";\n### Open a handle on a string, read it line-by-line, then close it:\n$SH = new IO::Scalar \\$data;\nwhile (defined($ = $SH->getline)) {\nprint \"Got line: $\";\n}\n$SH->close;\n### Open a handle on a string, and slurp in all the lines:\n$SH = new IO::Scalar \\$data;\nprint \"All lines:\\n\", $SH->getlines;\n### Get the current position (either of two ways):\n$pos = $SH->getpos;\n$offset = $SH->tell;\n### Set the current position (either of two ways):\n$SH->setpos($pos);\n$SH->seek($offset, 0);\n### Open an anonymous temporary scalar:\n$SH = new IO::Scalar;\n$SH->print(\"Hi there!\");\nprint \"I printed: \", ${$SH->sref}, \"\\n\";      ### get at value\nDon't like OO for your I/O? No problem. Thanks to the magic of an invisible tie(), the following\nnow works out of the box, just as it does with IO::Handle:\nuse 5.005;\nuse IO::Scalar;\n$data = \"My message:\\n\";\n### Open a handle on a string, and append to it:\n$SH = new IO::Scalar \\$data;\nprint $SH \"Hello\";\nprint $SH \", world!\\nBye now!\\n\";\nprint \"The string is now: \", $data, \"\\n\";\n### Open a handle on a string, read it line-by-line, then close it:\n$SH = new IO::Scalar \\$data;\nwhile (<$SH>) {\nprint \"Got line: $\";\n}\nclose $SH;\n### Open a handle on a string, and slurp in all the lines:\n$SH = new IO::Scalar \\$data;\nprint \"All lines:\\n\", <$SH>;\n### Get the current position (WARNING: requires 5.6):\n$offset = tell $SH;\n### Set the current position (WARNING: requires 5.6):\nseek $SH, $offset, 0;\n### Open an anonymous temporary scalar:\n$SH = new IO::Scalar;\nprint $SH \"Hi there!\";\nprint \"I printed: \", ${$SH->sref}, \"\\n\";      ### get at value\nAnd for you folks with 1.x code out there: the old tie() style still works, though this is\n*unnecessary and deprecated*:\nuse IO::Scalar;\n### Writing to a scalar...\nmy $s;\ntie *OUT, 'IO::Scalar', \\$s;\nprint OUT \"line 1\\nline 2\\n\", \"line 3\\n\";\nprint \"String is now: $s\\n\"\n### Reading and writing an anonymous scalar...\ntie *OUT, 'IO::Scalar';\nprint OUT \"line 1\\nline 2\\n\", \"line 3\\n\";\ntied(OUT)->seek(0,0);\nwhile (<OUT>) {\nprint \"Got line: \", $;\n}\nStringification works, too!\nmy $SH = new IO::Scalar \\$data;\nprint $SH \"Hello, \";\nprint $SH \"world!\";\nprint \"I printed: $SH\\n\";\n\n## DESCRIPTION\n\nThis class is part of the IO::Stringy distribution; see IO::Stringy for change log and general\ninformation.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **PUBLIC INTERFACE** (2 subsections)\n- **WARNINGS**\n- **VERSION**\n- **AUTHORS** (3 subsections)\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "IO::Scalar",
        "section": "",
        "mode": "perldoc",
        "summary": "IO::Scalar - IO:: interface for reading/writing a scalar",
        "synopsis": "Perform I/O on strings, using the basic OO interface...\nuse 5.005;\nuse IO::Scalar;\n$data = \"My message:\\n\";\n### Open a handle on a string, and append to it:\n$SH = new IO::Scalar \\$data;\n$SH->print(\"Hello\");\n$SH->print(\", world!\\nBye now!\\n\");\nprint \"The string is now: \", $data, \"\\n\";\n### Open a handle on a string, read it line-by-line, then close it:\n$SH = new IO::Scalar \\$data;\nwhile (defined($ = $SH->getline)) {\nprint \"Got line: $\";\n}\n$SH->close;\n### Open a handle on a string, and slurp in all the lines:\n$SH = new IO::Scalar \\$data;\nprint \"All lines:\\n\", $SH->getlines;\n### Get the current position (either of two ways):\n$pos = $SH->getpos;\n$offset = $SH->tell;\n### Set the current position (either of two ways):\n$SH->setpos($pos);\n$SH->seek($offset, 0);\n### Open an anonymous temporary scalar:\n$SH = new IO::Scalar;\n$SH->print(\"Hi there!\");\nprint \"I printed: \", ${$SH->sref}, \"\\n\";      ### get at value\nDon't like OO for your I/O? No problem. Thanks to the magic of an invisible tie(), the following\nnow works out of the box, just as it does with IO::Handle:\nuse 5.005;\nuse IO::Scalar;\n$data = \"My message:\\n\";\n### Open a handle on a string, and append to it:\n$SH = new IO::Scalar \\$data;\nprint $SH \"Hello\";\nprint $SH \", world!\\nBye now!\\n\";\nprint \"The string is now: \", $data, \"\\n\";\n### Open a handle on a string, read it line-by-line, then close it:\n$SH = new IO::Scalar \\$data;\nwhile (<$SH>) {\nprint \"Got line: $\";\n}\nclose $SH;\n### Open a handle on a string, and slurp in all the lines:\n$SH = new IO::Scalar \\$data;\nprint \"All lines:\\n\", <$SH>;\n### Get the current position (WARNING: requires 5.6):\n$offset = tell $SH;\n### Set the current position (WARNING: requires 5.6):\nseek $SH, $offset, 0;\n### Open an anonymous temporary scalar:\n$SH = new IO::Scalar;\nprint $SH \"Hi there!\";\nprint \"I printed: \", ${$SH->sref}, \"\\n\";      ### get at value\nAnd for you folks with 1.x code out there: the old tie() style still works, though this is\n*unnecessary and deprecated*:\nuse IO::Scalar;\n### Writing to a scalar...\nmy $s;\ntie *OUT, 'IO::Scalar', \\$s;\nprint OUT \"line 1\\nline 2\\n\", \"line 3\\n\";\nprint \"String is now: $s\\n\"\n### Reading and writing an anonymous scalar...\ntie *OUT, 'IO::Scalar';\nprint OUT \"line 1\\nline 2\\n\", \"line 3\\n\";\ntied(OUT)->seek(0,0);\nwhile (<OUT>) {\nprint \"Got line: \", $;\n}\nStringification works, too!\nmy $SH = new IO::Scalar \\$data;\nprint $SH \"Hello, \";\nprint $SH \"world!\";\nprint \"I printed: $SH\\n\";",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 97,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 26,
                "subsections": []
            },
            {
                "name": "PUBLIC INTERFACE",
                "lines": 1,
                "subsections": [
                    {
                        "name": "Construction",
                        "lines": 17
                    },
                    {
                        "name": "Input and output",
                        "lines": 67
                    }
                ]
            },
            {
                "name": "WARNINGS",
                "lines": 14,
                "subsections": []
            },
            {
                "name": "VERSION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "AUTHORS",
                "lines": 1,
                "subsections": [
                    {
                        "name": "Primary Maintainer",
                        "lines": 2
                    },
                    {
                        "name": "Principal author",
                        "lines": 2
                    },
                    {
                        "name": "Other contributors",
                        "lines": 20
                    }
                ]
            },
            {
                "name": "SEE ALSO",
                "lines": 7,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "IO::Scalar - IO:: interface for reading/writing a scalar\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "Perform I/O on strings, using the basic OO interface...\n\nuse 5.005;\nuse IO::Scalar;\n$data = \"My message:\\n\";\n\n### Open a handle on a string, and append to it:\n$SH = new IO::Scalar \\$data;\n$SH->print(\"Hello\");\n$SH->print(\", world!\\nBye now!\\n\");\nprint \"The string is now: \", $data, \"\\n\";\n\n### Open a handle on a string, read it line-by-line, then close it:\n$SH = new IO::Scalar \\$data;\nwhile (defined($ = $SH->getline)) {\nprint \"Got line: $\";\n}\n$SH->close;\n\n### Open a handle on a string, and slurp in all the lines:\n$SH = new IO::Scalar \\$data;\nprint \"All lines:\\n\", $SH->getlines;\n\n### Get the current position (either of two ways):\n$pos = $SH->getpos;\n$offset = $SH->tell;\n\n### Set the current position (either of two ways):\n$SH->setpos($pos);\n$SH->seek($offset, 0);\n\n### Open an anonymous temporary scalar:\n$SH = new IO::Scalar;\n$SH->print(\"Hi there!\");\nprint \"I printed: \", ${$SH->sref}, \"\\n\";      ### get at value\n\nDon't like OO for your I/O? No problem. Thanks to the magic of an invisible tie(), the following\nnow works out of the box, just as it does with IO::Handle:\n\nuse 5.005;\nuse IO::Scalar;\n$data = \"My message:\\n\";\n\n### Open a handle on a string, and append to it:\n$SH = new IO::Scalar \\$data;\nprint $SH \"Hello\";\nprint $SH \", world!\\nBye now!\\n\";\nprint \"The string is now: \", $data, \"\\n\";\n\n### Open a handle on a string, read it line-by-line, then close it:\n$SH = new IO::Scalar \\$data;\nwhile (<$SH>) {\nprint \"Got line: $\";\n}\nclose $SH;\n\n### Open a handle on a string, and slurp in all the lines:\n$SH = new IO::Scalar \\$data;\nprint \"All lines:\\n\", <$SH>;\n\n### Get the current position (WARNING: requires 5.6):\n$offset = tell $SH;\n\n### Set the current position (WARNING: requires 5.6):\nseek $SH, $offset, 0;\n\n### Open an anonymous temporary scalar:\n$SH = new IO::Scalar;\nprint $SH \"Hi there!\";\nprint \"I printed: \", ${$SH->sref}, \"\\n\";      ### get at value\n\nAnd for you folks with 1.x code out there: the old tie() style still works, though this is\n*unnecessary and deprecated*:\n\nuse IO::Scalar;\n\n### Writing to a scalar...\nmy $s;\ntie *OUT, 'IO::Scalar', \\$s;\nprint OUT \"line 1\\nline 2\\n\", \"line 3\\n\";\nprint \"String is now: $s\\n\"\n\n### Reading and writing an anonymous scalar...\ntie *OUT, 'IO::Scalar';\nprint OUT \"line 1\\nline 2\\n\", \"line 3\\n\";\ntied(OUT)->seek(0,0);\nwhile (<OUT>) {\nprint \"Got line: \", $;\n}\n\nStringification works, too!\n\nmy $SH = new IO::Scalar \\$data;\nprint $SH \"Hello, \";\nprint $SH \"world!\";\nprint \"I printed: $SH\\n\";\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This class is part of the IO::Stringy distribution; see IO::Stringy for change log and general\ninformation.\n\nThe IO::Scalar class implements objects which behave just like IO::Handle (or FileHandle)\nobjects, except that you may use them to write to (or read from) scalars. These handles are\nautomatically tiehandle'd (though please see \"WARNINGS\" for information relevant to your Perl\nversion).\n\nBasically, this:\n\nmy $s;\n$SH = new IO::Scalar \\$s;\n$SH->print(\"Hel\", \"lo, \");         ### OO style\n$SH->print(\"world!\\n\");            ### ditto\n\nOr this:\n\nmy $s;\n$SH = tie *OUT, 'IO::Scalar', \\$s;\nprint OUT \"Hel\", \"lo, \";           ### non-OO style\nprint OUT \"world!\\n\";              ### ditto\n\nCauses $s to be set to:\n\n\"Hello, world!\\n\"\n",
                "subsections": []
            },
            "PUBLIC INTERFACE": {
                "content": "",
                "subsections": [
                    {
                        "name": "Construction",
                        "content": "new [ARGS...]\n*Class method.* Return a new, unattached scalar handle. If any arguments are given, they're\nsent to open().\n\nopen [SCALARREF]\n*Instance method.* Open the scalar handle on a new scalar, pointed to by SCALARREF. If no\nSCALARREF is given, a \"private\" scalar is created to hold the file data.\n\nReturns the self object on success, undefined on error.\n\nopened\n*Instance method.* Is the scalar handle opened on something?\n\nclose\n*Instance method.* Disassociate the scalar handle from its underlying scalar. Done\nautomatically on destroy.\n"
                    },
                    {
                        "name": "Input and output",
                        "content": "flush\n*Instance method.* No-op, provided for OO compatibility.\n\nfileno\n*Instance method.* No-op, returns undef\n\ngetc\n*Instance method.* Return the next character, or undef if none remain.\n\ngetline\n*Instance method.* Return the next line, or undef on end of string. Can safely be called in\nan array context. Currently, lines are delimited by \"\\n\".\n\ngetlines\n*Instance method.* Get all remaining lines. It will croak() if accidentally called in a\nscalar context.\n\nprint ARGS...\n*Instance method.* Print ARGS to the underlying scalar.\n\nWarning: this continues to always cause a seek to the end of the string, but if you perform\nseek()s and tell()s, it is still safer to explicitly seek-to-end before subsequent print()s.\n\nread BUF, NBYTES, [OFFSET]\n*Instance method.* Read some bytes from the scalar. Returns the number of bytes actually\nread, 0 on end-of-file, undef on error.\n\nwrite BUF, NBYTES, [OFFSET]\n*Instance method.* Write some bytes to the scalar.\n\nsysread BUF, LEN, [OFFSET]\n*Instance method.* Read some bytes from the scalar. Returns the number of bytes actually\nread, 0 on end-of-file, undef on error.\n\nsyswrite BUF, NBYTES, [OFFSET]\n*Instance method.* Write some bytes to the scalar.\n\nSeeking/telling and other attributes\nautoflush\n*Instance method.* No-op, provided for OO compatibility.\n\nbinmode\n*Instance method.* No-op, provided for OO compatibility.\n\nclearerr\n*Instance method.* Clear the error and EOF flags. A no-op.\n\neof *Instance method.* Are we at end of file?\n\nseek OFFSET, WHENCE\n*Instance method.* Seek to a given position in the stream.\n\nsysseek OFFSET, WHENCE\n*Instance method.* Identical to \"seek OFFSET, WHENCE\", *q.v.*\n\ntell\n*Instance method.* Return the current position in the stream, as a numeric offset.\n\nsetpos POS\n*Instance method.* Set the current position, using the opaque value returned by \"getpos()\".\n\ngetpos\n*Instance method.* Return the current position in the string, as an opaque object.\n\nsref\n*Instance method.* Return a reference to the underlying scalar.\n"
                    }
                ]
            },
            "WARNINGS": {
                "content": "Perl's TIEHANDLE spec was incomplete prior to 5.00557; it was missing support for \"seek()\",\n\"tell()\", and \"eof()\". Attempting to use these functions with an IO::Scalar will not work prior\nto 5.00557. IO::Scalar will not have the relevant methods invoked; and even worse, this kind of\nbug can lie dormant for a while. If you turn warnings on (via $^W or \"perl -w\"), and you see\nsomething like this...\n\nattempt to seek on unopened filehandle\n\n...then you are probably trying to use one of these functions on an IO::Scalar with an old Perl.\nThe remedy is to simply use the OO version; e.g.:\n\n$SH->seek(0,0);    ### GOOD: will work on any 5.005\nseek($SH,0,0);     ### WARNING: will only work on 5.00557 and beyond\n",
                "subsections": []
            },
            "VERSION": {
                "content": "$Id: Scalar.pm,v 1.6 2005/02/10 21:21:53 dfs Exp $\n",
                "subsections": []
            },
            "AUTHORS": {
                "content": "",
                "subsections": [
                    {
                        "name": "Primary Maintainer",
                        "content": "Dianne Skoll (dfs@roaringpenguin.com).\n"
                    },
                    {
                        "name": "Principal author",
                        "content": "Eryq (eryq@zeegee.com). President, ZeeGee Software Inc (http://www.zeegee.com).\n"
                    },
                    {
                        "name": "Other contributors",
                        "content": "The full set of contributors always includes the folks mentioned in \"CHANGE LOG\" in IO::Stringy.\nBut just the same, special thanks to the following individuals for their invaluable\ncontributions (if I've forgotten or misspelled your name, please email me!):\n\n*Andy Glew,* for contributing \"getc()\".\n\n*Brandon Browning,* for suggesting \"opened()\".\n\n*David Richter,* for finding and fixing the bug in \"PRINTF()\".\n\n*Eric L. Brine,* for his offset-using read() and write() implementations.\n\n*Richard Jones,* for his patches to massively improve the performance of \"getline()\" and add\n\"sysread\" and \"syswrite\".\n\n*B. K. Oxley (binkley),* for stringification and inheritance improvements, and sundry good\nideas.\n\n*Doug Wilson,* for the IO::Handle inheritance and automatic tie-ing.\n"
                    }
                ]
            },
            "SEE ALSO": {
                "content": "IO::String, which is quite similar but which was designed more-recently and with an\nIO::Handle-like interface in mind, so you could mix OO- and native-filehandle usage without\nusing tied().\n\n*Note:* as of version 2.x, these classes all work like their IO::Handle counterparts, so we have\ncomparable functionality to IO::String.\n",
                "subsections": []
            }
        }
    }
}