Current Path : /compat/linux/proc/self/root/usr/opt/perl530/man/man3/ |
FreeBSD hs32.drive.ne.jp 9.1-RELEASE FreeBSD 9.1-RELEASE #1: Wed Jan 14 12:18:08 JST 2015 root@hs32.drive.ne.jp:/sys/amd64/compile/hs32 amd64 |
Current File : //compat/linux/proc/self/root/usr/opt/perl530/man/man3/IO::Handle.3 |
.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "IO::Handle 3" .TH IO::Handle 3 "2019-10-24" "perl v5.30.2" "Perl Programmers Reference Guide" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" IO::Handle \- supply object methods for I/O handles .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use IO::Handle; \& \& $io = IO::Handle\->new(); \& if ($io\->fdopen(fileno(STDIN),"r")) { \& print $io\->getline; \& $io\->close; \& } \& \& $io = IO::Handle\->new(); \& if ($io\->fdopen(fileno(STDOUT),"w")) { \& $io\->print("Some text\en"); \& } \& \& # setvbuf is not available by default on Perls 5.8.0 and later. \& use IO::Handle \*(Aq_IOLBF\*(Aq; \& $io\->setvbuf($buffer_var, _IOLBF, 1024); \& \& undef $io; # automatically closes the file if it\*(Aqs open \& \& autoflush STDOUT 1; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\f(CW\*(C`IO::Handle\*(C'\fR is the base class for all other \s-1IO\s0 handle classes. It is not intended that objects of \f(CW\*(C`IO::Handle\*(C'\fR would be created directly, but instead \f(CW\*(C`IO::Handle\*(C'\fR is inherited from by several other classes in the \s-1IO\s0 hierarchy. .PP If you are reading this documentation, looking for a replacement for the \f(CW\*(C`FileHandle\*(C'\fR package, then I suggest you read the documentation for \f(CW\*(C`IO::File\*(C'\fR too. .SH "CONSTRUCTOR" .IX Header "CONSTRUCTOR" .IP "new ()" 4 .IX Item "new ()" Creates a new \f(CW\*(C`IO::Handle\*(C'\fR object. .IP "new_from_fd ( \s-1FD, MODE\s0 )" 4 .IX Item "new_from_fd ( FD, MODE )" Creates an \f(CW\*(C`IO::Handle\*(C'\fR like \f(CW\*(C`new\*(C'\fR does. It requires two parameters, which are passed to the method \f(CW\*(C`fdopen\*(C'\fR; if the fdopen fails, the object is destroyed. Otherwise, it is returned to the caller. .SH "METHODS" .IX Header "METHODS" See perlfunc for complete descriptions of each of the following supported \f(CW\*(C`IO::Handle\*(C'\fR methods, which are just front ends for the corresponding built-in functions: .PP .Vb 10 \& $io\->close \& $io\->eof \& $io\->fcntl( FUNCTION, SCALAR ) \& $io\->fileno \& $io\->format_write( [FORMAT_NAME] ) \& $io\->getc \& $io\->ioctl( FUNCTION, SCALAR ) \& $io\->read ( BUF, LEN, [OFFSET] ) \& $io\->print ( ARGS ) \& $io\->printf ( FMT, [ARGS] ) \& $io\->say ( ARGS ) \& $io\->stat \& $io\->sysread ( BUF, LEN, [OFFSET] ) \& $io\->syswrite ( BUF, [LEN, [OFFSET]] ) \& $io\->truncate ( LEN ) .Ve .PP See perlvar for complete descriptions of each of the following supported \f(CW\*(C`IO::Handle\*(C'\fR methods. All of them return the previous value of the attribute and takes an optional single argument that when given will set the value. If no argument is given the previous value is unchanged (except for \f(CW$io\fR\->autoflush will actually turn \s-1ON\s0 autoflush by default). .PP .Vb 7 \& $io\->autoflush ( [BOOL] ) $| \& $io\->format_page_number( [NUM] ) $% \& $io\->format_lines_per_page( [NUM] ) $= \& $io\->format_lines_left( [NUM] ) $\- \& $io\->format_name( [STR] ) $~ \& $io\->format_top_name( [STR] ) $^ \& $io\->input_line_number( [NUM]) $. .Ve .PP The following methods are not supported on a per-filehandle basis. .PP .Vb 4 \& IO::Handle\->format_line_break_characters( [STR] ) $: \& IO::Handle\->format_formfeed( [STR]) $^L \& IO::Handle\->output_field_separator( [STR] ) $, \& IO::Handle\->output_record_separator( [STR] ) $\e \& \& IO::Handle\->input_record_separator( [STR] ) $/ .Ve .PP Furthermore, for doing normal I/O you might need these: .ie n .IP "$io\->fdopen ( \s-1FD, MODE\s0 )" 4 .el .IP "\f(CW$io\fR\->fdopen ( \s-1FD, MODE\s0 )" 4 .IX Item "$io->fdopen ( FD, MODE )" \&\f(CW\*(C`fdopen\*(C'\fR is like an ordinary \f(CW\*(C`open\*(C'\fR except that its first parameter is not a filename but rather a file handle name, an IO::Handle object, or a file descriptor number. (For the documentation of the \f(CW\*(C`open\*(C'\fR method, see IO::File.) .ie n .IP "$io\->opened" 4 .el .IP "\f(CW$io\fR\->opened" 4 .IX Item "$io->opened" Returns true if the object is currently a valid file descriptor, false otherwise. .ie n .IP "$io\->getline" 4 .el .IP "\f(CW$io\fR\->getline" 4 .IX Item "$io->getline" This works like <$io> described in \*(L"I/O Operators\*(R" in perlop except that it's more readable and can be safely called in a list context but still returns just one line. If used as the conditional within a \f(CW\*(C`while\*(C'\fR or C\-style \f(CW\*(C`for\*(C'\fR loop, however, you will need to emulate the functionality of <$io> with \f(CW\*(C`defined($_ = $io\->getline)\*(C'\fR. .ie n .IP "$io\->getlines" 4 .el .IP "\f(CW$io\fR\->getlines" 4 .IX Item "$io->getlines" This works like <$io> when called in a list context to read all the remaining lines in a file, except that it's more readable. It will also \fBcroak()\fR if accidentally called in a scalar context. .ie n .IP "$io\->ungetc ( \s-1ORD\s0 )" 4 .el .IP "\f(CW$io\fR\->ungetc ( \s-1ORD\s0 )" 4 .IX Item "$io->ungetc ( ORD )" Pushes a character with the given ordinal value back onto the given handle's input stream. Only one character of pushback per handle is guaranteed. .ie n .IP "$io\->write ( \s-1BUF, LEN\s0 [, \s-1OFFSET\s0 ] )" 4 .el .IP "\f(CW$io\fR\->write ( \s-1BUF, LEN\s0 [, \s-1OFFSET\s0 ] )" 4 .IX Item "$io->write ( BUF, LEN [, OFFSET ] )" This \f(CW\*(C`write\*(C'\fR is somewhat like \f(CW\*(C`write\*(C'\fR found in C, in that it is the opposite of read. The wrapper for the perl \f(CW\*(C`write\*(C'\fR function is called \f(CW\*(C`format_write\*(C'\fR. However, whilst the C \f(CW\*(C`write\*(C'\fR function returns the number of bytes written, this \f(CW\*(C`write\*(C'\fR function simply returns true if successful (like \f(CW\*(C`print\*(C'\fR). A more C\-like \f(CW\*(C`write\*(C'\fR is \f(CW\*(C`syswrite\*(C'\fR (see above). .ie n .IP "$io\->error" 4 .el .IP "\f(CW$io\fR\->error" 4 .IX Item "$io->error" Returns a true value if the given handle has experienced any errors since it was opened or since the last call to \f(CW\*(C`clearerr\*(C'\fR, or if the handle is invalid. It only returns false for a valid handle with no outstanding errors. .ie n .IP "$io\->clearerr" 4 .el .IP "\f(CW$io\fR\->clearerr" 4 .IX Item "$io->clearerr" Clear the given handle's error indicator. Returns \-1 if the handle is invalid, 0 otherwise. .ie n .IP "$io\->sync" 4 .el .IP "\f(CW$io\fR\->sync" 4 .IX Item "$io->sync" \&\f(CW\*(C`sync\*(C'\fR synchronizes a file's in-memory state with that on the physical medium. \f(CW\*(C`sync\*(C'\fR does not operate at the perlio api level, but operates on the file descriptor (similar to sysread, sysseek and systell). This means that any data held at the perlio api level will not be synchronized. To synchronize data that is buffered at the perlio api level you must use the flush method. \f(CW\*(C`sync\*(C'\fR is not implemented on all platforms. Returns \*(L"0 but true\*(R" on success, \f(CW\*(C`undef\*(C'\fR on error, \f(CW\*(C`undef\*(C'\fR for an invalid handle. See \fBfsync\fR\|(3c). .ie n .IP "$io\->flush" 4 .el .IP "\f(CW$io\fR\->flush" 4 .IX Item "$io->flush" \&\f(CW\*(C`flush\*(C'\fR causes perl to flush any buffered data at the perlio api level. Any unread data in the buffer will be discarded, and any unwritten data will be written to the underlying file descriptor. Returns \*(L"0 but true\*(R" on success, \f(CW\*(C`undef\*(C'\fR on error. .ie n .IP "$io\->printflush ( \s-1ARGS\s0 )" 4 .el .IP "\f(CW$io\fR\->printflush ( \s-1ARGS\s0 )" 4 .IX Item "$io->printflush ( ARGS )" Turns on autoflush, print \s-1ARGS\s0 and then restores the autoflush status of the \&\f(CW\*(C`IO::Handle\*(C'\fR object. Returns the return value from print. .ie n .IP "$io\->blocking ( [ \s-1BOOL\s0 ] )" 4 .el .IP "\f(CW$io\fR\->blocking ( [ \s-1BOOL\s0 ] )" 4 .IX Item "$io->blocking ( [ BOOL ] )" If called with an argument \f(CW\*(C`blocking\*(C'\fR will turn on non-blocking \s-1IO\s0 if \&\f(CW\*(C`BOOL\*(C'\fR is false, and turn it off if \f(CW\*(C`BOOL\*(C'\fR is true. .Sp \&\f(CW\*(C`blocking\*(C'\fR will return the value of the previous setting, or the current setting if \f(CW\*(C`BOOL\*(C'\fR is not given. .Sp If an error occurs \f(CW\*(C`blocking\*(C'\fR will return undef and \f(CW$!\fR will be set. .PP If the C functions \fBsetbuf()\fR and/or \fBsetvbuf()\fR are available, then \&\f(CW\*(C`IO::Handle::setbuf\*(C'\fR and \f(CW\*(C`IO::Handle::setvbuf\*(C'\fR set the buffering policy for an IO::Handle. The calling sequences for the Perl functions are the same as their C counterparts\*(--including the constants \f(CW\*(C`_IOFBF\*(C'\fR, \&\f(CW\*(C`_IOLBF\*(C'\fR, and \f(CW\*(C`_IONBF\*(C'\fR for \fBsetvbuf()\fR\-\-except that the buffer parameter specifies a scalar variable to use as a buffer. You should only change the buffer before any I/O, or immediately after calling flush. .PP \&\s-1WARNING:\s0 The \fBIO::Handle::setvbuf()\fR is not available by default on Perls 5.8.0 and later because \fBsetvbuf()\fR is rather specific to using the stdio library, while Perl prefers the new perlio subsystem instead. .PP \&\s-1WARNING: A\s0 variable used as a buffer by \f(CW\*(C`setbuf\*(C'\fR or \f(CW\*(C`setvbuf\*(C'\fR \fBmust not be modified\fR in any way until the IO::Handle is closed or \f(CW\*(C`setbuf\*(C'\fR or \&\f(CW\*(C`setvbuf\*(C'\fR is called again, or memory corruption may result! Remember that the order of global destruction is undefined, so even if your buffer variable remains in scope until program termination, it may be undefined before the file IO::Handle is closed. Note that you need to import the constants \f(CW\*(C`_IOFBF\*(C'\fR, \f(CW\*(C`_IOLBF\*(C'\fR, and \f(CW\*(C`_IONBF\*(C'\fR explicitly. Like C, setbuf returns nothing. setvbuf returns \*(L"0 but true\*(R", on success, \f(CW\*(C`undef\*(C'\fR on failure. .PP Lastly, there is a special method for working under \fB\-T\fR and setuid/gid scripts: .ie n .IP "$io\->untaint" 4 .el .IP "\f(CW$io\fR\->untaint" 4 .IX Item "$io->untaint" Marks the object as taint-clean, and as such data read from it will also be considered taint-clean. Note that this is a very trusting action to take, and appropriate consideration for the data source and potential vulnerability should be kept in mind. Returns 0 on success, \-1 if setting the taint-clean flag failed. (eg invalid handle) .SH "NOTE" .IX Header "NOTE" An \f(CW\*(C`IO::Handle\*(C'\fR object is a reference to a symbol/GLOB reference (see the \f(CW\*(C`Symbol\*(C'\fR package). Some modules that inherit from \f(CW\*(C`IO::Handle\*(C'\fR may want to keep object related variables in the hash table part of the \s-1GLOB.\s0 In an attempt to prevent modules trampling on each other I propose the that any such module should prefix its variables with its own name separated by _'s. For example the IO::Socket module keeps a \f(CW\*(C`timeout\*(C'\fR variable in 'io_socket_timeout'. .SH "SEE ALSO" .IX Header "SEE ALSO" perlfunc, \&\*(L"I/O Operators\*(R" in perlop, IO::File .SH "BUGS" .IX Header "BUGS" Due to backwards compatibility, all filehandles resemble objects of class \f(CW\*(C`IO::Handle\*(C'\fR, or actually classes derived from that class. They actually aren't. Which means you can't derive your own class from \f(CW\*(C`IO::Handle\*(C'\fR and inherit those methods. .SH "HISTORY" .IX Header "HISTORY" Derived from FileHandle.pm by Graham Barr <\fIgbarr@pobox.com\fR>