Debian Codegraph @

upstream/opensuse-tumbleweed/man3/IO::File.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\"
56 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "IO::File 3pm"
61 .TH IO::File 3pm 2026-03-09 "perl v5.42.1" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 IO::File \- supply object methods for filehandles
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 1
71 \& use IO::File;
72 \&
73 \& my $fh = IO::File\->new();
74 \& if ($fh\->open("< file")) {
75 \& print <$fh>;
76 \& $fh\->close;
77 \& }
78 \&
79 \& my $fh = IO::File\->new("> file");
80 \& if (defined $fh) {
81 \& print $fh "bar\en";
82 \& $fh\->close;
83 \& }
84 \&
85 \& my $fh = IO::File\->new("file", "r");
86 \& if (defined $fh) {
87 \& print <$fh>;
88 \& undef $fh; # automatically closes the file
89 \& }
90 \&
91 \& my $fh = IO::File\->new("file", O_WRONLY|O_APPEND);
92 \& if (defined $fh) {
93 \& print $fh "corge\en";
94 \&
95 \& my $pos = $fh\->getpos;
96 \& $fh\->setpos($pos);
97 \&
98 \& undef $fh; # automatically closes the file
99 \& }
100 \&
101 \& autoflush STDOUT 1;
102 .Ve
103 .SH DESCRIPTION
104 .IX Header "DESCRIPTION"
105 \&\f(CW\*(C`IO::File\*(C'\fR inherits from \f(CW\*(C`IO::Handle\*(C'\fR and \f(CW\*(C`IO::Seekable\*(C'\fR. It extends
106 these classes with methods that are specific to file handles.
107 .SH CONSTRUCTOR
108 .IX Header "CONSTRUCTOR"
109 .IP "new ( FILENAME [,MODE [,PERMS]] )" 4
110 .IX Item "new ( FILENAME [,MODE [,PERMS]] )"
111 Creates an \f(CW\*(C`IO::File\*(C'\fR. If it receives any parameters, they are passed to
112 the method \f(CW\*(C`open\*(C'\fR; if the open fails, the object is destroyed. Otherwise,
113 it is returned to the caller.
114 .IP new_tmpfile 4
115 .IX Item "new_tmpfile"
116 Creates an \f(CW\*(C`IO::File\*(C'\fR opened for read/write on a newly created temporary
117 file. On systems where this is possible, the temporary file is anonymous
118 (i.e. it is unlinked after creation, but held open). If the temporary
119 file cannot be created or opened, the \f(CW\*(C`IO::File\*(C'\fR object is destroyed.
120 Otherwise, it is returned to the caller.
121 .SH METHODS
122 .IX Header "METHODS"
123 .IP "open( FILENAME [,MODE [,PERMS]] )" 4
124 .IX Item "open( FILENAME [,MODE [,PERMS]] )"
125 .PD 0
126 .IP "open( FILENAME, IOLAYERS )" 4
127 .IX Item "open( FILENAME, IOLAYERS )"
128 .PD
129 \&\f(CW\*(C`open\*(C'\fR accepts one, two or three parameters. With one parameter,
130 it is just a front end for the built\-in \f(CW\*(C`open\*(C'\fR function. With two or three
131 parameters, the first parameter is a filename that may include
132 whitespace or other special characters, and the second parameter is
133 the open mode, optionally followed by a file permission value.
134 .Sp
135 If \f(CW\*(C`IO::File::open\*(C'\fR receives a Perl mode string (">", "+<", etc.)
136 or an ANSI C \fBfopen()\fR mode string ("w", "r+", etc.), it uses the basic
137 Perl \f(CW\*(C`open\*(C'\fR operator (but protects any special characters).
138 .Sp
139 If \f(CW\*(C`IO::File::open\*(C'\fR is given a numeric mode, it passes that mode
140 and the optional permissions value to the Perl \f(CW\*(C`sysopen\*(C'\fR operator.
141 The permissions default to 0666.
142 .Sp
143 If \f(CW\*(C`IO::File::open\*(C'\fR is given a mode that includes the \f(CW\*(C`:\*(C'\fR character,
144 it passes all the three arguments to the three\-argument \f(CW\*(C`open\*(C'\fR operator.
145 .Sp
146 For convenience, \f(CW\*(C`IO::File\*(C'\fR exports the O_XXX constants from the
147 Fcntl module, if this module is available.
148 .SH NOTE
149 .IX Header "NOTE"
150 Some operating systems may perform \f(CWIO::File::new()\fR or \f(CWIO::File::open()\fR
151 on a directory without errors. This behavior is not portable and not
152 suggested for use. Using \f(CWopendir()\fR and \f(CWreaddir()\fR or \f(CW\*(C`IO::Dir\*(C'\fR are
153 suggested instead.
154 .SH "SEE ALSO"
155 .IX Header "SEE ALSO"
156 perlfunc,
157 "I/O Operators" in perlop,
158 IO::Handle,
159 IO::Seekable,
160 IO::Dir
161 .SH HISTORY
162 .IX Header "HISTORY"
163 Derived from FileHandle.pm by Graham Barr <\[email protected]\fR>.