home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeJava and XSLTSearch this book

8.128. IO::Handle

The base class for all other IO handle classes. Its main purpose is for the other IO classes to inherit from it; programs should not create IO::Handle objects directly. Provides the following methods.

new

new

Constructor. Creates a new IO::Handle object.

new_from_fd

new_from_fd (fd, mode)

Constructor. Like new, creates an IO::Handle object. It requires two parameters, which are passed to the method fdopen; if fdopen fails, the object is destroyed. Otherwise, it is returned to the caller.

clearerr

$fh->clearerr

Clears the given handle's error indicator.

error

$fh->error

Returns true if the given handle has experienced any errors since it was opened or since the last call to clearerr.

fdopen

$fh->fdopen (fd, mode)

Like an ordinary open except that the first parameter is a filehandle name, an IO::Handle object, or a file descriptor number.

flush

$fh->flush

Flushes the given handle's buffer.

getline

$fh->getline

Works like <$fh>, described in the section on "I/O Operators" in the perlop manpage, but is more readable and can be safely called in an array context, while still returning one line.

getlines

$fh->getlines

Works like <$fh> when called in an array context to read all the remaining lines in a file, but is more readable. croak s if called in scalar context.

opened

$fh->opened

Returns true if the object is currently a valid file descriptor.

ungetc

$fh->ungetc (ord)

Pushes a character with the ordinal value ord back onto the given handle's input stream.

untaint

$fh->untaint

Special method for working under -T and setuid/gid scripts. Marks the object as taint-clean, and as such, data read from it is also considered taint-clean.

write

$fh->write (buf, len[, offset])

Like write found in C; that is, the opposite of read. The wrapper for the Perl write function is format_write.

IO::Handle also provides the following methods, which are not described in detail here because they are simply frontends for the corresponding built-in functions. See Chapter 5, "Function Reference" for more information.

Method

Description

close

Closes file or pipe

eof

Returns 1 if next read will return end-of-file

fileno

Returns file descriptor for a filehandle

getc

Returns next character from input file

print

Prints a string or comma-separated list of strings

printf

Prints a formatted string

read

Reads data from a filehandle

stat

Returns an array of status information for a file

sysread

Reads data from a filehandle with system call read(2)

syswrite

Writes data to a filehandle with system call write(2)

truncate

Truncates a file to a specified length

Finally, the following methods act on the equivalent Perl variables. See Chapter 4, "The Perl Language" for more information.

Method

Description

autoflush

If nonzero, forces a flush now and after each write or print (default 0)

format_page_number

Current page number

format_lines_per_page

Current page length (default 60)

format_lines_left

Number of lines left on page

format_name

Name of current report format

format_top_name

Name of current top-of-page format

format_line_break_characters

Current set of linebreak chars for a format

format_formfeed

Formfeed char used by formats (default \f)

format_write

Wrapper for write function

input_record_separator

Input record separator (default newline)

input_line_number

Current input line number for last filehandle accessed

output_field_separator

Output field separator for print

output_record_separator

Output record separator for print



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.