|
File Operations
Functions operating on a list of files return the number
of files successfully operated upon.
- chmod
LIST
- Changes the permissions of
a list of files. The first element of the list must be the
numerical mode.
- chown LIST
- Changes the owner and group
of a list of files. The first two elements of the list must
be the numerical uid and gid.
- truncate FILE,
SIZE
- Truncates FILE to SIZE. FILE
may be a filename or a filehandle.
- link OLDFILE,
NEWFILE
- Creates a new filename linked
to the old filename.
- lstat FILE
- Like stat, but does
not traverse a final symbolic link.
- mkdir DIR,
MODE
- Creates a directory with given
permissions. Sets $! on failure.
- readlink EXPR†
- Returns the value of a symbolic
link.
- rename OLDNAME,
NEWNAME
- Changes the name of a file.
- rmdir FILENAME†
- Deletes the directory if it
is empty. Sets $! on failure.
- stat FILE
- Returns a 13-element array
(0: $dev, 1: $ino,
2: $mode, 3: $nlink,
4: $uid, 5: $gid,
6: $rdev, 7: $size,
8: $atime, 9: $mtime,
10: $ctime, 11: $blksize,
12: $blocks). FILE can be a filehandle,
an expression evaluating to a filename, or _
to refer to the last file test operation or stat
call. Returns a null list if the stat fails.
- symlink OLDFILE, NEWFILE
- Creates a new filename symbolically
linked to the old filename.
- unlink LIST
- Deletes a list of files.
- utime LIST
- Changes the access and modification
times. The first two elements of the list must be the numerical
access and modification times.
|
Input / Output
In input/output operations, FILEHANDLE may be a filehandle
as opened by the open operator, a predefined filehandle
(e.g., STDOUT) or a scalar variable that evaluates
to the name of a filehandle to be used.
- <FILEHANDLE>
- In scalar context, reads a
single line from the file opened on FILEHANDLE. In array
context, reads the whole file.
- < >
- Reads from the input stream
formed by the files specified in @ARGV,
or standard input if no arguments were supplied.
- binmode FILEHANDLE
- Arranges for the file opened
on FILEHANDLE to be read or written in binary mode
as opposed to text mode (null operation on UNIX).
- close FILEHANDLE
- Closes the file or pipe associated
with the filehandle.
- dbmclose %HASH
- Deprecated, use untie
instead.
- dbmopen %HASH,
DBMNAME, MODE
- Deprecated, use tie
instead.
- eof FILEHANDLE
- Returns true if the
next read will return end of file, or if the file is not
open.
- eof
- Returns the EOF status for
the last file read.
- eof()
- Indicates EOF on the pseudo
file formed of the files listed on the command line.
- fcntl FILEHANDLE,
FUNCTION, $VAR
- Implements the fcntl(2)
function. This function has non-standard return values.
- fileno FILEHANDLE
- Returns the file descriptor
for a given (open) file.
- flock FILEHANDLE,
OPERATION
- Calls flock(2) on the
file. OPERATION formed by adding 1 (shared), 2 (exclusive),
4 (non-blocking), or 8 (unlock).
- getc [ FILEHANDLE ]
- Yields the next character from
the file, or an empty string on end of file. If FILEHANDLE
is omitted, reads from STDIN.
- ioctl FILEHANDLE,
FUNCTION, $VAR
- Performs ioctl(2) on
the file. This function has non-standard return values.
- print [ FILEHANDLE ]
[ LIST† ]
- Equivalent to print
FILEHANDLE sprintf LIST.
- printf[([FILEHANDLE]
LIST†)*]
- Equivalent to print
FILEHANDLE sprintf(LIST).
-
|
- open FILEHANDLE [ ,
FILENAME ]
- Opens a file and associates it with FILEHANDLE.
If FILENAME is omitted, the scalar variable of the same
name as the FILEHANDLE must contain the filename.
The following filename conventions apply when opening a
file.
| "FILE" |
open FILE for input.
Also "<FILE". |
| ">FILE" |
open FILE for output,
creating it if necessary. |
| ">>FILE" |
open FILE in append mode. |
| "+<FILE" |
open FILE with read/write
access (file must exist). |
| "+>FILE" |
open FILE with read/write
access (file truncated). |
| "|CMD" |
opens a pipe to command
CMD; forks if CMD is -. |
| "CMD|" |
opens a pipe from command
CMD; forks if CMD is -. |
FILE may be &FILEHND
in which case the new filehandle is connected to the (previously
opened) filehandle FILEHND. If it is &=N,
FILE will be connected to the given file descriptor. open
returns undef upon failure, true otherwise.
- pipe READHANDLE,
WRITEHANDLE)
- Returns a pair of connected
pipes.
-
- read FILEHANDLE,
$VAR, LENGTH [ ,
OFFSET ]
- Reads LENGTH binary bytes from
the file into the variable at OFFSET. Returns number of
bytes actually read.
- seek FILEHANDLE,
POSITION, WHENCE
- Arbitarily positions the file.
Returns true if successful.
- select [ FILEHANDLE
]
- Returns the currently selected
filehandle. Sets the current default filehandle for output
operations if FILEHANDLE is supplied.
- select RBITS,
WBITS, NBITS, TIMEOUT
- Performs a select(2)
system call with the same parameters.
- sprintf FORMAT,
LIST
- Returns a string formatted
by (almost all of) the usual printf(3) conventions.
- sysread FILEHANDLE,
$VAR, LENGTH [ ,
OFFSET ]
- Reads LENGTH bytes into $VAR
at OFFSET.
- syswrite FILEHANDLE,
SCALAR, LENGTH [ , OFFSET
]
- Writes LENGTH bytes from SCALAR
at OFFSET.
- tell [ FILEHANDLE ]
- Returns the current file position
for the file. If FILENAME is omitted, assumes the file last
read.
- write [ FILEHANDLE ]
- Writes a formatted record to
the specified file, using the format associated with that
file.
|