1IO::File(3pm)          Perl Programmers Reference Guide          IO::File(3pm)
2
3
4

NAME

6       IO::File - supply object methods for filehandles
7

SYNOPSIS

9           use IO::File;
10
11           $fh = IO::File->new();
12           if ($fh->open("< file")) {
13               print <$fh>;
14               $fh->close;
15           }
16
17           $fh = IO::File->new("> file");
18           if (defined $fh) {
19               print $fh "bar\n";
20               $fh->close;
21           }
22
23           $fh = IO::File->new("file", "r");
24           if (defined $fh) {
25               print <$fh>;
26               undef $fh;       # automatically closes the file
27           }
28
29           $fh = IO::File->new("file", O_WRONLY|O_APPEND);
30           if (defined $fh) {
31               print $fh "corge\n";
32
33               $pos = $fh->getpos;
34               $fh->setpos($pos);
35
36               undef $fh;       # automatically closes the file
37           }
38
39           autoflush STDOUT 1;
40

DESCRIPTION

42       "IO::File" inherits from "IO::Handle" and "IO::Seekable". It extends
43       these classes with methods that are specific to file handles.
44

CONSTRUCTOR

46       new ( FILENAME [,MODE [,PERMS]] )
47           Creates an "IO::File".  If it receives any parameters, they are
48           passed to the method "open"; if the open fails, the object is
49           destroyed.  Otherwise, it is returned to the caller.
50
51       new_tmpfile
52           Creates an "IO::File" opened for read/write on a newly created
53           temporary file.  On systems where this is possible, the temporary
54           file is anonymous (i.e. it is unlinked after creation, but held
55           open).  If the temporary file cannot be created or opened, the
56           "IO::File" object is destroyed.  Otherwise, it is returned to the
57           caller.
58

METHODS

60       open( FILENAME [,MODE [,PERMS]] )
61       open( FILENAME, IOLAYERS )
62           "open" accepts one, two or three parameters.  With one parameter,
63           it is just a front end for the built-in "open" function.  With two
64           or three parameters, the first parameter is a filename that may
65           include whitespace or other special characters, and the second
66           parameter is the open mode, optionally followed by a file
67           permission value.
68
69           If "IO::File::open" receives a Perl mode string (">", "+<", etc.)
70           or an ANSI C fopen() mode string ("w", "r+", etc.), it uses the
71           basic Perl "open" operator (but protects any special characters).
72
73           If "IO::File::open" is given a numeric mode, it passes that mode
74           and the optional permissions value to the Perl "sysopen" operator.
75           The permissions default to 0666.
76
77           If "IO::File::open" is given a mode that includes the ":"
78           character, it passes all the three arguments to the three-argument
79           "open" operator.
80
81           For convenience, "IO::File" exports the O_XXX constants from the
82           Fcntl module, if this module is available.
83
84       binmode( [LAYER] )
85           "binmode" sets "binmode" on the underlying "IO" object, as
86           documented in "perldoc -f binmode".
87
88           "binmode" accepts one optional parameter, which is the layer to be
89           passed on to the "binmode" call.
90

NOTE

92       Some operating systems may perform  "IO::File::new()" or
93       "IO::File::open()" on a directory without errors.  This behavior is not
94       portable and not suggested for use.  Using "opendir()" and "readdir()"
95       or "IO::Dir" are suggested instead.
96

SEE ALSO

98       perlfunc, "I/O Operators" in perlop, IO::Handle, IO::Seekable, IO::Dir
99

HISTORY

101       Derived from FileHandle.pm by Graham Barr <gbarr@pobox.com>.
102
103
104
105perl v5.32.1                      2021-03-31                     IO::File(3pm)
Impressum