{
    "content": [
        {
            "type": "text",
            "text": "# FileHandle (man)\n\n## NAME\n\nFileHandle - supply object methods for filehandles\n\n## SYNOPSIS\n\nuse FileHandle;\n$fh = FileHandle->new;\nif ($fh->open(\"< file\")) {\nprint <$fh>;\n$fh->close;\n}\n$fh = FileHandle->new(\"> FOO\");\nif (defined $fh) {\nprint $fh \"bar\\n\";\n$fh->close;\n}\n$fh = FileHandle->new(\"file\", \"r\");\nif (defined $fh) {\nprint <$fh>;\nundef $fh;       # automatically closes the file\n}\n$fh = FileHandle->new(\"file\", OWRONLY|OAPPEND);\nif (defined $fh) {\nprint $fh \"corge\\n\";\nundef $fh;       # automatically closes the file\n}\n$pos = $fh->getpos;\n$fh->setpos($pos);\n$fh->setvbuf($buffervar, IOLBF, 1024);\n($readfh, $writefh) = FileHandle::pipe;\nautoflush STDOUT 1;\n\n## DESCRIPTION\n\nNOTE: This class is now a front-end to the IO::* classes.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "FileHandle",
        "section": "",
        "mode": "man",
        "summary": "FileHandle - supply object methods for filehandles",
        "synopsis": "use FileHandle;\n$fh = FileHandle->new;\nif ($fh->open(\"< file\")) {\nprint <$fh>;\n$fh->close;\n}\n$fh = FileHandle->new(\"> FOO\");\nif (defined $fh) {\nprint $fh \"bar\\n\";\n$fh->close;\n}\n$fh = FileHandle->new(\"file\", \"r\");\nif (defined $fh) {\nprint <$fh>;\nundef $fh;       # automatically closes the file\n}\n$fh = FileHandle->new(\"file\", OWRONLY|OAPPEND);\nif (defined $fh) {\nprint $fh \"corge\\n\";\nundef $fh;       # automatically closes the file\n}\n$pos = $fh->getpos;\n$fh->setpos($pos);\n$fh->setvbuf($buffervar, IOLBF, 1024);\n($readfh, $writefh) = FileHandle::pipe;\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": 35,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 87,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "FileHandle - supply object methods for filehandles\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use FileHandle;\n\n$fh = FileHandle->new;\nif ($fh->open(\"< file\")) {\nprint <$fh>;\n$fh->close;\n}\n\n$fh = FileHandle->new(\"> FOO\");\nif (defined $fh) {\nprint $fh \"bar\\n\";\n$fh->close;\n}\n\n$fh = FileHandle->new(\"file\", \"r\");\nif (defined $fh) {\nprint <$fh>;\nundef $fh;       # automatically closes the file\n}\n\n$fh = FileHandle->new(\"file\", OWRONLY|OAPPEND);\nif (defined $fh) {\nprint $fh \"corge\\n\";\nundef $fh;       # automatically closes the file\n}\n\n$pos = $fh->getpos;\n$fh->setpos($pos);\n\n$fh->setvbuf($buffervar, IOLBF, 1024);\n\n($readfh, $writefh) = FileHandle::pipe;\n\nautoflush STDOUT 1;\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "NOTE: This class is now a front-end to the IO::* classes.\n\n\"FileHandle::new\" creates a \"FileHandle\", which is a reference to a newly created symbol (see\nthe \"Symbol\" package).  If it receives any parameters, they are passed to \"FileHandle::open\";\nif the open fails, the \"FileHandle\" object is destroyed.  Otherwise, it is returned to the\ncaller.\n\n\"FileHandle::newfromfd\" creates a \"FileHandle\" like \"new\" does.  It requires two\nparameters, which are passed to \"FileHandle::fdopen\"; if the fdopen fails, the \"FileHandle\"\nobject is destroyed.  Otherwise, it is returned to the caller.\n\n\"FileHandle::open\" accepts one parameter or two.  With one parameter, it is just a front end\nfor the built-in \"open\" function.  With two parameters, the first parameter is a filename\nthat may include whitespace or other special characters, and the second parameter is the open\nmode, optionally followed by a file permission value.\n\nIf \"FileHandle::open\" receives a Perl mode string (\">\", \"+<\", etc.)  or a POSIX fopen() mode\nstring (\"w\", \"r+\", etc.), it uses the basic Perl \"open\" operator.\n\nIf \"FileHandle::open\" is given a numeric mode, it passes that mode and the optional\npermissions value to the Perl \"sysopen\" operator.  For convenience, \"FileHandle::import\"\ntries to import the OXXX constants from the Fcntl module.  If dynamic loading is not\navailable, this may fail, but the rest of FileHandle will still work.\n\n\"FileHandle::fdopen\" is like \"open\" except that its first parameter is not a filename but\nrather a file handle name, a FileHandle object, or a file descriptor number.\n\nIf the C functions fgetpos() and fsetpos() are available, then \"FileHandle::getpos\" returns\nan opaque value that represents the current position of the FileHandle, and\n\"FileHandle::setpos\" uses that value to return to a previously visited position.\n\nIf the C function setvbuf() is available, then \"FileHandle::setvbuf\" sets the buffering\npolicy for the FileHandle.  The calling sequence for the Perl function is the same as its C\ncounterpart, including the macros \"IOFBF\", \"IOLBF\", and \"IONBF\", except that the buffer\nparameter specifies a scalar variable to use as a buffer.  WARNING: A variable used as a\nbuffer by \"FileHandle::setvbuf\" must not be modified in any way until the FileHandle is\nclosed or until \"FileHandle::setvbuf\" is called again, or memory corruption may result!\n\nSee perlfunc for complete descriptions of each of the following supported \"FileHandle\"\nmethods, which are just front ends for the corresponding built-in functions:\n\nclose\nfileno\ngetc\ngets\neof\nclearerr\nseek\ntell\n\nSee perlvar for complete descriptions of each of the following supported \"FileHandle\"\nmethods:\n\nautoflush\noutputfieldseparator\noutputrecordseparator\ninputrecordseparator\ninputlinenumber\nformatpagenumber\nformatlinesperpage\nformatlinesleft\nformatname\nformattopname\nformatlinebreakcharacters\nformatformfeed\n\nFurthermore, for doing normal I/O you might need these:\n\n$fh->print\nSee \"print\" in perlfunc.\n\n$fh->printf\nSee \"printf\" in perlfunc.\n\n$fh->getline\nThis works like <$fh> described in \"I/O Operators\" in perlop except that it's more\nreadable and can be safely called in a list context but still returns just one line.\n\n$fh->getlines\nThis works like <$fh> 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\nThere are many other functions available since FileHandle is descended from IO::File,\nIO::Seekable, and IO::Handle.  Please see those respective pages for documentation on more\nfunctions.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "The IO extension, perlfunc, \"I/O Operators\" in perlop.\n\n\n\nperl v5.34.0                                 2025-07-25                            FileHandle(3perl)",
                "subsections": []
            }
        }
    }
}