1IO::File(3pm) Perl Programmers Reference Guide IO::File(3pm)
2
3
4
6 IO::File - supply object methods for filehandles
7
9 use IO::File;
10
11 $fh = new IO::File;
12 if ($fh->open("< file")) {
13 print <$fh>;
14 $fh->close;
15 }
16
17 $fh = new IO::File "> file";
18 if (defined $fh) {
19 print $fh "bar\n";
20 $fh->close;
21 }
22
23 $fh = new IO::File "file", "r";
24 if (defined $fh) {
25 print <$fh>;
26 undef $fh; # automatically closes the file
27 }
28
29 $fh = new IO::File "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
42 "IO::File" inherits from "IO::Handle" and "IO::Seekable". It extends
43 these classes with methods that are specific to file handles.
44
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 tem‐
53 porary file. On systems where this is possible, the temporary file
54 is anonymous (i.e. it is unlinked after creation, but held open).
55 If the temporary file cannot be created or opened, the "IO::File"
56 object is destroyed. Otherwise, it is returned to the caller.
57
59 open( FILENAME [,MODE [,PERMS]] )
60 open( FILENAME, IOLAYERS )
61 "open" accepts one, two or three parameters. With one parameter,
62 it is just a front end for the built-in "open" function. With two
63 or three parameters, the first parameter is a filename that may
64 include whitespace or other special characters, and the second
65 parameter is the open mode, optionally followed by a file permis‐
66 sion value.
67
68 If "IO::File::open" receives a Perl mode string (">", "+<", etc.)
69 or an ANSI C fopen() mode string ("w", "r+", etc.), it uses the
70 basic Perl "open" operator (but protects any special characters).
71
72 If "IO::File::open" is given a numeric mode, it passes that mode
73 and the optional permissions value to the Perl "sysopen" operator.
74 The permissions default to 0666.
75
76 If "IO::File::open" is given a mode that includes the ":" charac‐
77 ter, it passes all the three arguments to the three-argument "open"
78 operator.
79
80 For convenience, "IO::File" exports the O_XXX constants from the
81 Fcntl module, if this module is available.
82
83 binmode( [LAYER] )
84 "binmode" sets "binmode" on the underlying "IO" object, as docu‐
85 mented in "perldoc -f binmode".
86
87 "binmode" accepts one optional parameter, which is the layer to be
88 passed on to the "binmode" call.
89
91 Some operating systems may perform "IO::File::new()" or
92 "IO::File::open()" on a directory without errors. This behavior is not
93 portable and not suggested for use. Using "opendir()" and "readdir()"
94 or "IO::Dir" are suggested instead.
95
97 perlfunc, "I/O Operators" in perlop, IO::Handle, IO::Seekable, IO::Dir
98
100 Derived from FileHandle.pm by Graham Barr <gbarr@pobox.com>.
101
102
103
104perl v5.8.8 2001-09-21 IO::File(3pm)