{
    "content": [
        {
            "type": "text",
            "text": "# IO::Handle (perldoc)\n\n**Summary:** IO::Handle - supply object methods for I/O handles\n\n**Synopsis:** use IO::Handle;\n$io = IO::Handle->new();\nif ($io->fdopen(fileno(STDIN),\"r\")) {\nprint $io->getline;\n$io->close;\n}\n$io = IO::Handle->new();\nif ($io->fdopen(fileno(STDOUT),\"w\")) {\n$io->print(\"Some text\\n\");\n}\n# setvbuf is not available by default on Perls 5.8.0 and later.\nuse IO::Handle 'IOLBF';\n$io->setvbuf($buffervar, IOLBF, 1024);\nundef $io;       # automatically closes the file if it's open\nautoflush STDOUT 1;\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (21 lines)\n- **DESCRIPTION** (7 lines)\n- **CONSTRUCTOR** (8 lines)\n- **METHODS** (114 lines) — 1 subsections\n  - setvbuf (18 lines)\n- **NOTE** (6 lines)\n- **SEE ALSO** (2 lines)\n- **BUGS** (4 lines)\n- **HISTORY** (2 lines)\n\n## Full Content\n\n### NAME\n\nIO::Handle - supply object methods for I/O handles\n\n### SYNOPSIS\n\nuse IO::Handle;\n\n$io = IO::Handle->new();\nif ($io->fdopen(fileno(STDIN),\"r\")) {\nprint $io->getline;\n$io->close;\n}\n\n$io = IO::Handle->new();\nif ($io->fdopen(fileno(STDOUT),\"w\")) {\n$io->print(\"Some text\\n\");\n}\n\n# setvbuf is not available by default on Perls 5.8.0 and later.\nuse IO::Handle 'IOLBF';\n$io->setvbuf($buffervar, IOLBF, 1024);\n\nundef $io;       # automatically closes the file if it's open\n\nautoflush STDOUT 1;\n\n### DESCRIPTION\n\n\"IO::Handle\" is the base class for all other IO handle classes. It is not intended that objects\nof \"IO::Handle\" would be created directly, but instead \"IO::Handle\" is inherited from by several\nother classes in the IO hierarchy.\n\nIf you are reading this documentation, looking for a replacement for the \"FileHandle\" package,\nthen I suggest you read the documentation for \"IO::File\" too.\n\n### CONSTRUCTOR\n\nnew ()\nCreates a new \"IO::Handle\" object.\n\nnewfromfd ( FD, MODE )\nCreates an \"IO::Handle\" like \"new\" does. It requires two parameters, which are passed to the\nmethod \"fdopen\"; if the fdopen fails, the object is destroyed. Otherwise, it is returned to\nthe caller.\n\n### METHODS\n\nSee perlfunc for complete descriptions of each of the following supported \"IO::Handle\" methods,\nwhich are just front ends for the corresponding built-in functions:\n\n$io->close\n$io->eof\n$io->fcntl( FUNCTION, SCALAR )\n$io->fileno\n$io->formatwrite( [FORMATNAME] )\n$io->getc\n$io->ioctl( FUNCTION, SCALAR )\n$io->read ( BUF, LEN, [OFFSET] )\n$io->print ( ARGS )\n$io->printf ( FMT, [ARGS] )\n$io->say ( ARGS )\n$io->stat\n$io->sysread ( BUF, LEN, [OFFSET] )\n$io->syswrite ( BUF, [LEN, [OFFSET]] )\n$io->truncate ( LEN )\n\nSee perlvar for complete descriptions of each of the following supported \"IO::Handle\" methods.\nAll of them return the previous value of the attribute and takes an optional single argument\nthat when given will set the value. If no argument is given the previous value is unchanged\n(except for $io->autoflush will actually turn ON autoflush by default).\n\n$io->autoflush ( [BOOL] )                         $|\n$io->formatpagenumber( [NUM] )                  $%\n$io->formatlinesperpage( [NUM] )               $=\n$io->formatlinesleft( [NUM] )                   $-\n$io->formatname( [STR] )                         $~\n$io->formattopname( [STR] )                     $^\n$io->inputlinenumber( [NUM])                    $.\n\nThe following methods are not supported on a per-filehandle basis.\n\nIO::Handle->formatlinebreakcharacters( [STR] ) $:\nIO::Handle->formatformfeed( [STR])               $^L\nIO::Handle->outputfieldseparator( [STR] )       $,\nIO::Handle->outputrecordseparator( [STR] )      $\\\n\nIO::Handle->inputrecordseparator( [STR] )       $/\n\nFurthermore, for doing normal I/O you might need these:\n\n$io->fdopen ( FD, MODE )\n\"fdopen\" is like an ordinary \"open\" except that its first parameter is not a filename but\nrather a file handle name, an IO::Handle object, or a file descriptor number. (For the\ndocumentation of the \"open\" method, see IO::File.)\n\n$io->opened\nReturns true if the object is currently a valid file descriptor, false otherwise.\n\n$io->getline\nThis works like <$io> described in \"I/O Operators\" in perlop except that it's more readable\nand can be safely called in a list context but still returns just one line. If used as the\nconditional within a \"while\" or C-style \"for\" loop, however, you will need to emulate the\nfunctionality of <$io> with \"defined($ = $io->getline)\".\n\n$io->getlines\nThis works like <$io> when called in a list context to read all the remaining lines in a\nfile, except that it's more readable. It will also croak() if accidentally called in a\nscalar context.\n\n$io->ungetc ( ORD )\nPushes a character with the given ordinal value back onto the given handle's input stream.\nOnly one character of pushback per handle is guaranteed.\n\n$io->write ( BUF, LEN [, OFFSET ] )\nThis \"write\" is somewhat like \"write\" found in C, in that it is the opposite of read. The\nwrapper for the perl \"write\" function is called \"formatwrite\". However, whilst the C\n\"write\" function returns the number of bytes written, this \"write\" function simply returns\ntrue if successful (like \"print\"). A more C-like \"write\" is \"syswrite\" (see above).\n\n$io->error\nReturns a true value if the given handle has experienced any errors since it was opened or\nsince the last call to \"clearerr\", or if the handle is invalid. It only returns false for a\nvalid handle with no outstanding errors.\n\n$io->clearerr\nClear the given handle's error indicator. Returns -1 if the handle is invalid, 0 otherwise.\n\n$io->sync\n\"sync\" synchronizes a file's in-memory state with that on the physical medium. \"sync\" does\nnot operate at the perlio api level, but operates on the file descriptor (similar to\nsysread, sysseek and systell). This means that any data held at the perlio api level will\nnot be synchronized. To synchronize data that is buffered at the perlio api level you must\nuse the flush method. \"sync\" is not implemented on all platforms. Returns \"0 but true\" on\nsuccess, \"undef\" on error, \"undef\" for an invalid handle. See fsync(3c).\n\n$io->flush\n\"flush\" causes perl to flush any buffered data at the perlio api level. Any unread data in\nthe buffer will be discarded, and any unwritten data will be written to the underlying file\ndescriptor. Returns \"0 but true\" on success, \"undef\" on error.\n\n$io->printflush ( ARGS )\nTurns on autoflush, print ARGS and then restores the autoflush status of the \"IO::Handle\"\nobject. Returns the return value from print.\n\n$io->blocking ( [ BOOL ] )\nIf called with an argument \"blocking\" will turn on non-blocking IO if \"BOOL\" is false, and\nturn it off if \"BOOL\" is true.\n\n\"blocking\" will return the value of the previous setting, or the current setting if \"BOOL\"\nis not given.\n\nIf an error occurs \"blocking\" will return undef and $! will be set.\n\nIf the C functions setbuf() and/or setvbuf() are available, then \"IO::Handle::setbuf\" and\n\"IO::Handle::setvbuf\" set the buffering policy for an IO::Handle. The calling sequences for the\nPerl functions are the same as their C counterparts--including the constants \"IOFBF\", \"IOLBF\",\nand \"IONBF\" for setvbuf()--except that the buffer parameter specifies a scalar variable to use\nas a buffer. You should only change the buffer before any I/O, or immediately after calling\nflush.\n\nWARNING: The IO::Handle::setvbuf() is not available by default on Perls 5.8.0 and later because\n\n#### setvbuf\n\nsubsystem instead.\n\nWARNING: A variable used as a buffer by \"setbuf\" or \"setvbuf\" must not be modified in any way\nuntil the IO::Handle is closed or \"setbuf\" or \"setvbuf\" is called again, or memory corruption\nmay result! Remember that the order of global destruction is undefined, so even if your buffer\nvariable remains in scope until program termination, it may be undefined before the file\nIO::Handle is closed. Note that you need to import the constants \"IOFBF\", \"IOLBF\", and\n\"IONBF\" explicitly. Like C, setbuf returns nothing. setvbuf returns \"0 but true\", on success,\n\"undef\" on failure.\n\nLastly, there is a special method for working under -T and setuid/gid scripts:\n\n$io->untaint\nMarks the object as taint-clean, and as such data read from it will also be considered\ntaint-clean. Note that this is a very trusting action to take, and appropriate consideration\nfor the data source and potential vulnerability should be kept in mind. Returns 0 on\nsuccess, -1 if setting the taint-clean flag failed. (eg invalid handle)\n\n### NOTE\n\nAn \"IO::Handle\" object is a reference to a symbol/GLOB reference (see the \"Symbol\" package).\nSome modules that inherit from \"IO::Handle\" may want to keep object related variables in the\nhash table part of the GLOB. In an attempt to prevent modules trampling on each other I propose\nthe that any such module should prefix its variables with its own name separated by 's. For\nexample the IO::Socket module keeps a \"timeout\" variable in 'iosockettimeout'.\n\n### SEE ALSO\n\nperlfunc, \"I/O Operators\" in perlop, IO::File\n\n### BUGS\n\nDue to backwards compatibility, all filehandles resemble objects of class \"IO::Handle\", or\nactually classes derived from that class. They actually aren't. Which means you can't derive\nyour own class from \"IO::Handle\" and inherit those methods.\n\n### HISTORY\n\nDerived from FileHandle.pm by Graham Barr <gbarr@pobox.com>\n\n"
        }
    ],
    "structuredContent": {
        "command": "IO::Handle",
        "section": "",
        "mode": "perldoc",
        "summary": "IO::Handle - supply object methods for I/O handles",
        "synopsis": "use IO::Handle;\n$io = IO::Handle->new();\nif ($io->fdopen(fileno(STDIN),\"r\")) {\nprint $io->getline;\n$io->close;\n}\n$io = IO::Handle->new();\nif ($io->fdopen(fileno(STDOUT),\"w\")) {\n$io->print(\"Some text\\n\");\n}\n# setvbuf is not available by default on Perls 5.8.0 and later.\nuse IO::Handle 'IOLBF';\n$io->setvbuf($buffervar, IOLBF, 1024);\nundef $io;       # automatically closes the file if it's open\nautoflush STDOUT 1;",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 21,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 7,
                "subsections": []
            },
            {
                "name": "CONSTRUCTOR",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "METHODS",
                "lines": 114,
                "subsections": [
                    {
                        "name": "setvbuf",
                        "lines": 18
                    }
                ]
            },
            {
                "name": "NOTE",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "HISTORY",
                "lines": 2,
                "subsections": []
            }
        ]
    }
}