Table A.1. Perl Functions
Function | Description |
---|
abs | abs VALUE
Returns the absolute value of its argument ($_ is the default). Ignores signs. |
accept | accept(NEWSOCKET, GENERICSOCKET)
Accepts a socket connection from clients waiting for a connection.
GENERICSOCKET, a filehandle, has been previously opened by the socket function, is bound to an address, and is listening for a connection.
NEWSOCKET is a filehandle with the same properties as GENERICSOCKET. The accept function attaches GENERICSOCKET to the newly made connection.
See accept(2). |
alarm | alarm(SECONDS)
alarm SECONDS
Sends a SIGALARM signal to the process after a number of SECONDS.
See alarm(3). |
atan2 | atan2(X,Y)
Returns the arctangent of X/Y in the range <pi>. |
bind | bind(SOCKET, NAME)
Binds an address, NAME, to an already opened unnamed socket, SOCKET.
See bind(2). |
binmode | binmode(FILEHANDLE)
binmode FILEHANDLE
For operating systems that distinguish between text and "binary" mode (not UNIX). Prepares the FILEHANDLE for reading in binary mode. |
bless | bless(REFERENCE, CLASS)
bless REFERENCE
Tells the object referenced by REFERENCE that it is an object in a package (CLASS) in the current package if no CLASS is specified. Returns the reference. |
caller | caller(EXPR)
caller EXPR
caller
Returns an array with information about the subroutine call stack, including the package, filename, and line number. With EXPR, a number, the function seeks backward EXPR stack frames before the current one. |
chdir | chdir(EXPR)
chdir EXPR
chdir
Changes the present working directory to EXPR. If EXPR is omitted, changes directory to home directory.
See chdir(2). |
chmod | chmod(MODE, LIST)
chmod MODE, LIST
Changes permissions of a list of files; first argument is the permission MODE number (octal); the remaining arguments are a list of filenames. Returns the number of files changed.
See chmod(2). |
chomp | chomp(LIST)
chomp(VARIABLE)
chomp VARIABLE
chomp
Chops off the last character of a string, VARIABLE, or the last character of each item in a LIST if that character corresponds to the current value of $/, which is by default set to the newline. Unlike chop (see following), it returns the number of characters deleted. |
chop | chop(LIST)
chop(VARIABLE)
chop VARIABLE
chop
Chops off the last character of a string, VARIABLE, or the last character of each item in a LIST and returns the chopped value. Without an argument, chops the last character off $_. |
chown | chown(LIST)
chown LIST
Changes the owner and group IDs of a list of files. First two elements in the list are the numerical uid and gid, respectively. The rest of the list are the names of files. Returns the number of files changed.
See chown(2). |
chr | chr NUMBER
Returns the ASCII value for NUMBER; e.g., chr(66) returns B. |
chroot | chroot(FILENAME)
chroot FILENAME
Changes root directory for the current process to FILENAME, which is the starting point for pathnames starting with /. Must be superuser to do this.
See chroot(2). |
close | close(FILEHANDLE)
close FILEHANDLE
Closes the file, socket, or pipe associated with FILEHANDLE. |
closedir | closedir(DIRHANDLE)
closedir DIRHANDLE
Closes a directory structure opened by opendir.
See directory(3). |
connect | connect(SOCKET, NAME)
Connects a process with one that is waiting for an accept call. NAME is a packed network address.
See connect(2). |
cos | cos(EXPR)
cos EXPR
Returns the cosine of EXPR (in radians). |
crypt | crypt(PLAINTEXT, SALT)
The password encryption function, where PLAINTEXT is the user's password and SALT is a two-character string consisting of characters in the set [a–zA–Z./].
See crypt(3). |
dbmclose | dbmclose(%ASSOC_ARRAY)
dbmclose %ASSOC_ARRAY
Breaks the binding between a DBM file and an associative array. Useful only with NDBM, a newer version of DBM, if supported.
See untie.
See dbm(3). |
dbmopen | dbmopen(%ASSOC_ARRAY, DBNAME, MODE)
Binds a DBM or NDBM file to an associative array. Before a database can be accessed, it must be opened by dbmopen. The files file.dir and file.pag must exist. DBNAME is the name of the file without the .dir and .pag extension. If the database does not exist and permission MODE is specified, the database is created.
See tie.
See dbminit(3). |
defined | defined(EXPR)
defined EXPR
Returns a Boolean value 1 if EXPR has a real value. Returns a Boolean value 0 if EXPR does not have a real value. EXPR may be a scalar, array, hash, or subroutine. For a hash, checks only whether the value (not key) is defined. |
delete | delete $ASSOC{KEY}
Deletes a value from an associative array. If successful, returns the deleted value; otherwise, returns an undefined value. If a value in %ENV is deleted, the environment will be modified. The undef function can also be used and is faster. |
die | die(LIST)
die LIST
die
Prints the LIST to STDERR and exits with the value of $!, the system error message (errno). When in an eval function, sets the $@ value to the error message, and aborts eval. If the value of LIST does not end in a newline, the name of the current script, the line number, and a newline are appended to the message. |
do | do BLOCK
do SUBROUTINE(LIST)
do EXPR
do BLOCK returns the value of the last command in the BLOCK.
do SUBROUTINE(LIST) calls a SUBROUTINE that has been defined.
do EXPR uses EXPR as a filename and executes the contents of the file as a Perl script. Used primarily to include subroutines from the Perl subroutine library. |
dump | dump LABEL
Causes an immediate binary image core dump. The undump command, used for undumping a core file, is not part of the Perl 5.6.0 distribution. |
each | each(%ASSOC_ARRAY)
each %ASSOC_ARRAY
Returns a two-element array, the key and value for the next value of an associative array, in random order. |
eof | eof(FILEHANDLE)
eof()
eof
Returns 1 if the next read on FILEHANDLE indicates the end of file. If FILEHANDLE is omitted, it returns the end of file for the last file read. |
eval | eval(EXPR)
eval EXPR
Evaluates EXPR as a Perl program in the context of the current Perl script. Often used for trapping otherwise fatal errors. Syntax errors or runtime errors or those coming from the die function are returned to the $@ variable. The $@ variable is set to NULL if there are no errors. The value returned is the value of the last expression evaluated. |
exec | exec(LIST)
exec LIST
Executes a system command LIST in context of the current program. Never returns. If LIST is scalar, checks for shell metacharacters and passes them to /bin/sh. Otherwise, arguments are passed to the C function call execvp. Does not flush output buffer. |
exists | exists EXPR
Returns TRUE if a specified key from an associative array exists, even if its corresponding value is undefined. |
exit | exit(INTEGER)
exit INTEGER
Exits with script with status value of INTEGER. If INTEGER is omitted, exits with 0, meaning the program exits with successful status. A nonzero status implies that something went wrong in the program. |
exp | exp(EXPR)
exp EXPR
The exponential function. Returns e to the power of EXPR. |
fcntl | fcntl(FILEHANDLE, FUNCTION, SCALAR)
Changes properties on an open file. Requires sys/fcntl.ph. The FUNCTION can duplicate an existing file descriptor, get or set file descriptor flags, get or set file status flags, get or set asynchronous I/O ownership, and get or set record locks. SCALAR is an integer for flags.
See fcntl(2). |
fileno | fileno(FILEHANDLE)
fileno FILEHANDLE
Returns the integer file descriptor for FILEHANDLE. Descriptors start with STDIN, STDOUT, STDERR, 0, 1, and 2, respectively. May not be reliable in Perl scripts if a file is closed and reopened.
See ferror(3). |
flock | flock(FILEHANDLE, OPERATION)
Applies or removes advisory locks on files. OPERATION specifies an operation on a lock for a file, shared locks, exclusive locks, or nonblocking locks. The OPERATION to remove a file is unlock.
See flock(2). |
fork | fork
Creates a new (child) process. The child is a copy of the parent process. Both child and parent continue execution with the instruction immediately following the fork. Returns 0 to the child process and the pid of the child to the parent. |
format | format NAME = picture line value list ... .
Declares a set of picture lines to describe the layout of corresponding values. The write function uses the specified format to send output to a named filehandle represented by NAME. If NAME is omitted, the default is STDOUT. |
formline | formline PICTURE, LIST
An internal function used by format to format a list of values according to the picture line. Can also be called directly in a program. |
getc | getc(FILEHANDLE)
getc FILEHANDLE
getc
Returns the next character from the input file associated with FILEHANDLE. Returns a NULL string at EOF. If FILEHANDLE is omitted, reads from STDIN. |
getgrent | getgrent
setgrent
endgrent
Iterates through /etc/group and returns an entry from /etc/group as a list, including group name, password, group ID (gid), and members.
See getgrent(3). |
getgrgid | getgrgid(GID)
Returns a group entry file by group number.
See getgrgid(3). |
getgrnam | getgrnam(NAME)
Returns a group file entry by group name.
See getgrent(3). |
gethostbyaddr | gethostbyaddr(ADDRESS, AF_INET)
Translates a network address to its corresponding names and alternative addresses. Returns the hostname, aliases, address type, length, and unpacked raw addresses. AF_INET is always 2.
See gethostbyaddr(3). |
gethostbyname | gethostbyname(HOSTNAME)
Translates a hostname to an entry from the /etc/hosts file as a list, including the hostname, aliases, addresses. In scalar context, returns only the host address.
See gethostbyname(3). |
gethostent | gethostent
sethostent(STAYOPEN)
endhostent
Iterates through /etc/hosts file and returns the entry as a list, including name, aliases, addresss type, length, and alternative addresses. Returns a list from the network host database, /etc/hosts.
See gethostent(3). |
getlogin | getlogin
Returns the current login from /etc/utmp, if there is such a file. If getlogin does not work, try
$loginname = getlogin || (getpwuid($<))[0] || die "Not a user here"
See getlogin(3). |
getnetbyaddr | getnetbyaddr(ADDR, ADDRESSTYPE)
Translates a network address to its corresponding network name or names. Returns a list from the network database, /etc/networks. In scalar context, returns only the network name.
See getnetent(3). |
getnetbyname | getnetbyname(NAME)
Translates a network name to its corresponding network address. Returns a list from the network database, /etc/networks. In scalar context, returns only the network address.
See getnetent(3). |
getnetent | getnetent
setnetent(STAYOPEN)
endnetent
Iterates through the /etc/networks file and returns the entry as a list. Returns a list from the network database,/etc/networks. In scalar context, returns only the network name.
See getnetent(3). |
getpeername | getpeername(SOCKET)
Returns the packed sockaddr address of other end of the SOCKET connection.
See getpeername(2). |
getpgrp | getpgrp(PID)
getpgrp PID
Returns the current process group for the specified PID (PID 0 is the current process). Without EXPR, returns the process group of the current process.
See getpgrp(2). |
getppid | getppid
Returns the pid of the parent process. If 1 is returned, that is the pid for init. Init adopts a process whose parent has died.
See getpid(2). |
getpriority | getpriority(WHICH, WHO)
Returns the current priority, nice value, for WHICH––a process, a process group, or a user. WHO is relative to WHICH group. A WHO value of zero denotes the current process, process group, or user.
See getpriority(2). |
getprotobyname | getprotobyname(NAME)
Translates a protocol NAME to its corresponding number and returns a list including the protocol name, aliases, and the protocol number. Returns a line from the network protocol database, /etc/protocols.
See getprotoent(3). |
getprotobynumber | getprotobynumber(NUMBER)
Translates a protocol NUMBER to its corresponding name and returns a list including the protocol name, aliases, and the protocol number. Returns a line from the network protocol database, /etc/protocols.
See getprotoent(3). |
getprotoent | getprotoent
setprotent(STAYOPEN)
endprotoent
Returns a list from the /etc/protocols database, including the protocol name, aliases, and the protocol number. If the STAYOPEN flag is nonzero, the database will not be closed during subsequent calls. The endprotoent function closes the file. In scalar context, returns the protocol name.
See getprotoent(3). |
getpwent | getpwent
setpwent
endpwent
Iterates through the /etc/passwd file and returns the entry as a list, username, password, uid, gid, quotas, comment, gcos field, home directory, and startup shell. The endpwent function closes the file. In scalar context, returns the username.
See getpwent(3). |
getpwnam | getpwnam(NAME)
Translates a username to the corresponding entry in /etc/passwd file. Returns a list, including the username, password, uid, gid, quotas, comment, gcos field, home directory, and startup shell. In scalar context, returns the numeric user ID.
See getpwent(3). |
getpwuid | getpwuid(UID)
Translates the numeric user ID to the corresponding entry from the /etc/passwd file. Returns a list, including the username, password, uid, gid, quotas, comment, gcos field, home directory, and startup shell. In scalar context, returns the username.
See getpwent(3). |
getservbyname | getservbyname(NAME, PROTOCOL)
From /etc/services database, translates a port name to its corresponding port number as a scalar and, returns as an array, the service name, aliases, port where service resides and protocol needed from the /etc/services database. In scalar context, returns only the service port number.
See getservent(3). |
getservbyport | getservbyport(PORT_NUMBER, PROTOCOL)
From /etc/services database, translates a port number to its corresponding port name as a scalar and returns as an array the service name, aliases, port where service resides, and protocol needed, from the /etc/services database. In scalar context, returns only the service port number.
See getservent(3). |
getservent | getservent
setservent(STAYOPEN)
endservent
Iterates through the /etc/services database, returning the service name, aliases, port where service resides, and protocol needed. If STAYOPEN flag is nonzero, the database will not be closed during subsequent calls and endservent closes the file. In scalar context, returns only the service port name.
See getservent(3). |
getsockname | getsockname(SOCKET)
Returns the packed sockaddr address of the local end of the SOCKET connection.
See getsockname(2). |
getsockopt | getsockopt(SOCKET, LEVEL, OPTNAME)
Returns the requested options, OPTNAME, associated with SOCKET at the specified protocol LEVEL.
See getsockopt(2). |
glob | glob EXPR
Performs filename expansion on EXPR as the shell does. Without EXPR, $_ is used. Uses the internal <*> operator. |
gmtime | gmtime(EXPR)
gmtime EXPR
Converts the results of the time function to a 9-element array with the Greenwich Mean Time zone, including the second, minute, hour, day of the month, month, year, day of the week, day of the year, and 1 if daylight saving time is in effect.
See ctime(3) and timegm() in the Perl library module Time::Local. |
goto | goto LABEL
goto EXPR
goto &NAME
Program branches to the LABEL and resumes execution. Cannot goto any construct that requires intialization, such as a subroutine or foreach loop. Goto never returns a value. The form goto &NAME substitutes the currently running subroutine with a call to NAME (used by the AUTOLOAD subroutine). |
grep | grep(EXPR, LIST)
grep BLOCK LIST
Returns to a new array any element in LIST where EXPR matches that element. Returns a scalar, the number of matches. |
hex | hex(EXPR)
hex EXPR
Returns the decimal value of EXPR interpreted as a hexadecimal string. Without EXPR, uses $_. |
import | import CLASSNAME LIST
import CLASSNAME
Not a built-in function but a class method defined by modules that will export names to other modules through the use function. |
index | index(STR, SUBSTR, POSITION)
index(STR, SUBSTR)
Returns the position of the first occurrence of SUBSTR in STR. POSITION specifies a starting position for the substring in the string starting with base 0. |
int | int(EXPR)
int EXPR
Returns the integer portion of EXPR. Without EXPR, $_ is used. |
ioctl | ioctl(FILEHANDLE, FUNCTION, SCALAR)
Used to control I/O operations, mainly terminal I/O. Requires sys/ioctl.ph. FUNCTION is an I/O request. SCALAR will be read or written depending on the request.
See ioctl(2). |
join | join(EXPR, LIST)
Returns a single string by joining the separate strings of LIST into a single string where the field separator is specified by EXPR, a delimiter. |
keys | keys(%ASSOC_ARRAY)
keys %ASSOC_ARRAY
Returns a normal array consisting of all the keys in the associative array. |
kill | kill(SIGNAL, PROCESS_LIST)
kill PROCESS_LIST
Sends a SIGNAL to a list of processes. The SIGNAL can be either a number or a signal name (signal name must be quoted). (Negative SIGNAL number kills process group.)
See kill(2). |
last | last LABEL
last
The last command is comparable to C's break command. It exits the innermost loop or, if the loop is labeled last LABEL, exits that loop. |
lc | lc EXPR
Returns EXPR in lowercase. Same as \L \E escape sequence. |
lcfirst | lcfirst EXPR
Returns EXPR with the first character in lowercase. Same as \l \E sequence. |
length | length(EXPR)
length EXPR
Returns the length in characters of scalar EXPR or, if EXPR is omitted, returns length of $_. Not used to find the size of an array or associative array. |
link | link(OLDFILE, NEWFILE)
Creates a hard link. NEWFILE is another name for OLDFILE.
See link(2). |
listen | listen(SOCKET, QUEUESIZE)
Listens for connections on a SOCKET with a QUEUESIZE specifying the number of processes waiting for connections.
See listen(2). |
local | local(LIST)
Makes variables in LIST local for this block, subroutine, or eval. |
localtime | localtime(EXPR)
localtime EXPR
Converts the time returned by the time function to a 9-element array for the local time zone. The array consists of
seconds minutes hours day of the month number of the month (0 is January) years since 1990 day of the week (0 is Sunday) day of the year (0 is January 1) isdst (true if daylight savings is on)
See ctime(3). |
lock | lock THING
Places a lock on a variable, subroutine, or object referenced by THING until the lock goes out of scope. Used only with threads if they are enabled. |
log | log(EXPR)
log EXPR
Returns the logarithm (base e) of EXPR. If EXPR is omitted, returns log($_). |
lstat | lstat(FILEHANDLE)
lstat FILEHANDLE
lstat(EXPR)
Returns a 14-element array consisting of file statistics on a symbolic link, rather than the file the symbolic link points to. The array consists of
device file inode number file mode number of hard links to the file user ID of owner group ID of owner raw device size of file file last access time file last modify time file last status change time preferred block size for filesystem I/O actual number of blocks allocated
See stat(2). |
m | /PATTERN/
m/PATTERN/
m is the match operator that interprets PATTERN as a regular expression and is used when alternative delimeters are needed, such as m!PATTERN!. |
map | map(BLOCK LIST)
map(EXPR, LIST)
Evaluates BLOCK or EXPR for each element of LIST and returns the list value containing the results of the evaluation. The following example translates a list of numbers to characters: @chars = map chr, @numbers |
mkdir | mkdir(NAME, MODE)
Creates a directory, NAME, with MODE permissions (octal).
See mkdir(2). |
msgctl | msgctl(MSGID, CMD, FLAGS)
Calls the msgctl system call, allowing control operations on a message queue. Has weird return codes. Requires library files ipc.ph and msg.ph.
See System V IPC.
See also msgctl(2). |
msgget | msgget(KEY, FLAGS)
Calls msgget system call. Returns the message queue ID number or, if undefined, an error.
See System V IPC.
See also msgget(2). |
msgrcv | msgrcv(MSGID, VAR, MSG_SIZE, TYPE, FLAGS)
Calls the msgrv system call. Receives a message from the message queue, stores the message in VAR. MSG_SIZE is the maximum message size, and TYPE is the message type.
See System V IPC.
See also msgrcv(2). |
msgsnd | msgsnd(ID, MSG, FLAGS)
Calls the msgsnd system call. Sends the message MSG to the message queue. MSG must begin with the message type. The pack function is used to create the message.
See System V IPC.
See also msgsnd(2). |
my | my TYPE EXPR : ATTRIBUTES
my EXPR : ATTRIBUTES
my TYPE EXPR
my EXPR
Variables declared with the my function are made private; i.e., they exist only within the innermost enclosing block, subroutine, eval, or file. Only simple scalars, complete arrays, and hashes can be declared with my. TYPE and ATTRIBUTES optional and experimental at this time. |
new | new CLASSNAME LIST
new CLASSNAME
Not a built-in function but a constructor method defined by the CLASSNAME module for creating CLASSNAME-type objects. Convention taken from C++. |
next | next LABEL
next
Starts the next iteration of the innermost or loop labeled with LABEL. Like the C continue function. |
no | no Module LIST
If a pragma or module has been imported with use, the no function says you don't want to use it anymore. |
not | not EXPR
Logically negates the truth value of EXPR. |
oct | oct(EXPR)
oct EXPR
oct
Returns the decimal value of EXPR, an octal string. If EXPR contains a leading 0x, EXPR is interpreted as hex. With no EXPR, $_ is converted. |
open | open(FILEHANDLE, EXPR)
open(FILEHANDLE)
open FILEHANDLE
Opens a real file, EXPR, and attaches it to FILEHANDLE. Without EXPR, a scalar with the same name as FILEHANDLE must have been assigned that filename. |
| read
| "FILEHANDLE" |
| write
| ">FILEHANDLE" |
| read/write
| "+>FILEHANDLE" |
| append
| ">>FILEHANDLE" |
| pipe out
| "| UNIX Command" |
| pipe in
| "UNIX Command |" |
opendir | opendir(DIRHANDLE, EXPR)
Opens a directory structure named EXPR and attaches it to DIRHANDLE for functions that examine the structure.
See directory(3). |
ord | ord(EXPR)
ord
Returns the unsigned numeric ASCII values of the first character of EXPR. If EXPR is omitted, $_ is used. |
our | our TYPE EXPR : ATTRIBUTES
our EXPR : ATTRIBUTES
our TYPE EXPR
our EXPR
Declares one or more variables to be valid globals within the enclosing block, file, or eval. Like my for globals but does not create a new private variable. Useful when the strict pragma is turned on and a global variable is wanted. |
pack | $packed=pack(TEMPLATE, LIST)
Packs a list of values into a binary structure and returns the structure. TEMPLATE is a quoted string containing the number and type of value.
TEMPLATE is |
| a | An ASCII string, null padded |
| A | An ASCII string, space padded |
| b | A bit string, low-to-high order |
| B | A bit string, high-to-low order |
| h | A hexadecimal string, low nybble first |
| H | A hexadecimal string, high nybble first |
| c | A signed char value |
| C | An unsigned char value |
| s | A signed short value |
| S | An unsigned short value |
| i | A signed integer value |
| I | An unsigned integer value |
| l | A signed long value |
| L | An unsigned long value |
| n | A short in "network" order |
| N | A long in "network" order |
| f | A single-precision float in native format |
| d | A double-precision float in native format |
| p | A pointer to a string |
| x | A null byte |
| X | Back up a byte |
| @ | Null-fill to absolute precision |
| u | A uuencoded string |
package | package NAMESPACE
A package declaration creates a separate namespace (symbol table) for NAMESPACE, the Perl way of creating a class. The NAMESPACE belongs to the rest of the innermost enclosing block, subroutine, eval, or file. If the package declaration is at the same level, the new one overrides the old one. |
pipe | pipe(READHANDLE, WRITEHANDLE)
Opens a pipe for reading and writing, normally after a fork.
See pipe(2). |
pop | pop(ARRAY)
pop ARRAY
Pops and returns the last element of the array. The array will have one less element. |
pos | pos(SCALAR)
pos SCALAR
Returns the offset of the character after the last matched search in SCALAR left off; i.e., the position where the next search will start. Offsets start at 0. If the $scalar is a signed "hello" and the search is $scalar =~ m/l/g, the pos function would return the position of the character after the first l, position 3. |
print | print(FILEHANDLE LIST)
print(LIST)
print FILEHANDLE LIST
print LIST
print
Prints a string or a comma-separated list of strings to FILEHANDLE or to the currently selected FILEHANDLE or to STDOUT, the default. Retuns 1 if successful, 0 if not. |
printf | printf(FILEHANDLE FORMAT, LIST)
printf(FORMAT, LIST)
Prints a formatted string to FILEHANDLE or, if FILEHANDLE is omitted, to the currently selected output filehandle. STDOUT is the default. Similar to C's printf, except * is not supported.
See printf(3). |
prototype | prototype FUNCTION
Returns the prototype of a function as a string, where FUNCTION is the name of the function. Returns undef if there is no prototype. |
push | push(ARRAY, LIST)
Pushes the values in LIST onto the end of the ARRAY. The array will be increased. Returns the new length of ARRAY. |
q, qq, qw, qx | q/STRING/
qq/STRING/
qw/LIST/
qx/COMMAND/
An alternative form of quoting. The q construct treats STRING as if enclosed in single quotes. The qq construct treats STRING as if enclosed in double quotes. The qw construct treats each element of LIST as if enclosed in single quotes, and the qx treats COMMAND as if in backquotes. |
quotemeta | quotemeta EXPR
Returns the scalar value of EXPR with all regular expression metacharacters backslashed. |
rand | rand(EXPR)
rand EXPR
rand
Returns a random fractional number (scalar) between 0 and EXPR, where EXPR is a positive number. Without srand generates the same sequence of numbers. If EXPR is omitted, returns a value between 0 and 1.
See rand(3). |
read | read(FILEHANDLE, SCALAR, LENGTH, OFFSET)
read(FILEHANDLE, SCALAR, LENGTH)
Reads LENGTH number of bytes from FILEHANDLE, starting at position OFFSET, into SCALAR and returns the number of bytes read, or 0 if EOF. (Similar to fread system call.)
See fread(3). |
readdir | readdir(DIRHANDLE)
readdir DIRHANDLE
Reads the next entry of the directory structure, DIRHANDLE, opened by opendir. See directory(3). |
readline | readline FILEHANDLE
Reads and returns a line from selected FILEHANDLE;
e.g., $line = readline(STDIN). |
readlink | readlink(EXPR)
readlink EXPR
Returns the value of a symbolic link. EXPR is the pathname of the symbolic link, and if omitted, $_ is used. See readlink(2). |
readpipe | readpipe scalar EXPR
readpipe LIST(proposed)
An internal function that implements the qw// quote construct or backquotes for command subsitution; e.g., to print the output of the UNIX ls command, type print reapipe(ls). |
recv | recv(SOCKET, SCALAR, LEN, FLAGS)
Receives a message of LEN bytes on a socket into SCALAR variable. Returns the address of the sender.
See recv(2). |
redo | redo LABEL
redo
Restarts a loop block without reevaluting the condition. If there is a continue block, it is not executed. Without LABEL, restarts at the innermost enclosing loop. |
ref | ref EXPR
Returns a scalar TRUE value, the data type of EXPR, if EXPR is a reference, else the NULL string. The returned value depends on what is being referenced, a REF, SCALAR, ARRAY, HASH, CODE, or GLOB. If EXPR is an object that has been blessed into a package, the return value is the package (class) name. |
rename | rename(OLDNAME, NEWNAME)
Renames a file OLDNAME to NEWNAME. Does not work across filesystem boundaries. If NEWNAME already exists, it is destroyed.
See rename(2). |
require | require(EXPR)
require EXPR
require
Includes file EXPR from the Perl library by searching the @INC array for the specified file. Also checks that the library has not already been included. $_ is used if EXPR is omitted. |
reset | reset(EXPR)
reset EXPR
reset
Clears variables and arrays or, if EXPR is omitted, resets ?? searches. |
return | return LIST
Returns a value from a subroutine. Cannot be used outside of a subroutine. |
reverse | reverse(LIST)
Reverses the order of LIST and returns an array. |
rewinddir | rewinddir(DIRHANDLE)
rewinddir DIRHANDLE
Rewinds the position in DIRHANDLE to the beginning of the directory structure.
See directory(3). |
rindex | rindex(STRING, SUBSTR, OFFSET)
rindex(STRING, SUBSTR)
Returns the last position of SUBSTR in STRING starting at OFFSET, if OFFSET is specified like index but returns the last position of the substring rather than the first. |
rmdir | rmdir(FILENAME)
rmdir FILENAME
Removes a directory, FILENAME, if empty. |
s | s/SEARCH_PATTERN/REPLACEMENT/[g][i][e][o]
Searches for SEARCH_PATTERN and, if found, replaces the pattern with some text. Returns the number of substitutions made. The g option is global across a line. The i option turns off case sensitivity. The e option evaluates the replacement string as an expression; e.g., s/\d+/$ &+5/e |
scalar | scalar(EXPR)
Forces EXPR to be evaluated in a scalar context. |
seek | seek(FILEHANDLE, POSITION, WHENCE)
Positions a file pointer in a file, FILEHANDLE, from some position, relative to its postition in the file WHENCE. If WHENCE is 0, starts at the beginning of the file; if WHENCE is 1, starts at the current position of the file, and if WHENCE is 2, starts at the end of the file. POSITION cannot be negative if WHENCE is 0. |
seekdir | seekdir(DIRHANDLE, POSITION)
Sets the POSITION for the readdir function on the directory structure associated with DIRHANDLE.
See directory(3). |
select | select(FILEHANDLE)
select
Returns the currently selected filehandle if FILEHANDLE is omitted. With FILEHANDLE, sets the current default filehandle for write and print.
See Formatting. |
select | select(RBITS, WBITS, EBITS, TIMEOUT)
Examines the I/O file descriptors to see if descriptors are ready for reading or writing or have exceptional conditions pending. Bitmasks are specified, and TIMEOUT is in seconds.
See select(2). |
semctl | semctl(ID, SEMNUM, CMD, ARG)
Calls the semctl system call, allowing control operations on semaphores. Has weird return codes. Requires library files ipc.ph and sem.ph.
See System V IPC.
See also semctl(2). |
semget | semget(KEY, NSEMS, SIZE, FLAGS)
Returns the semaphore ID associated with KEY, or undefined if an error. Requires library files ipc.ph and sem.ph.
See System V IPC.
See also semget(2). |
semop | semop(KEY, OPSTRING)
Calls the semop system call to perform operations on a semaphore identified by KEY. OPSTRING must be a packed array of semop structures. Requires library files ipc.ph and sem.ph.
See System V IPC.
See also semop(2). |
send | send(SOCKET, MSG, FLAGS,TO)
send(SOCKET, MSG, FLAGS)
Sends a message on a SOCKET.
See send(2). |
setpgrp | setpgrp(PID, PGRP)
Sets the current process group for the specified process, process group, or user.
See getpgrp(2). |
setpriority | setpriority(WHICH,WHO, PRIORITY)
Sets the current priority, nice value, for a process, process group, or user.
See getpriority(2). |
setsockopt | setsockopt(SOCKET, LEVEL, OPTNAME, OPTVAL)
Sets the requested socket option on SOCKET.
See getsockopt(2). |
shift | shift(ARRAY)
shift ARRAY
shift
Shifts off the first value of the ARRAY and returns it, shortening the array. If ARRAY is omitted, the @ARGV array is shifted, and if in subroutines, the @_ array is shifted. |
shmctl | shmctl(ID, CMD, ARG)
Calls the shmctl system call, allowing control operations on shared memory. Has weird return codes. Requires library file ipc.ph and shm.ph.
See System V IPC.
See also shmctl(2). |
shmget | shmget(KEY, SIZE, FLAGS)
Returns the shared memory segment ID associated with the KEY, or undefined if an error. The shared memory segment created is of at least SIZE bytes.
Requires ipc.ph and shm.ph.
See System V IPC.
See also shmget(2). |
shmread | shmread(ID, VAR, POS, SIZE)
Reads from the shared memory ID starting at position POS for SIZE. VAR is a variable used to store what is read. The segment is attached, data is read from, and the segment is detached. Requires ipc.ph and shm.ph.
See System V IPC.
See also shmat(2). |
shmwrite | shmwrite(ID, VAR, POS, SIZE)
Writes to the shared memory ID starting at position POS for SIZE. VAR is a variable used to store what is written. The segment is attached, data is written to, and the segment is detached. Requires ipc.ph and shm.ph.
See System V IPC.
See also shmat(2). |
shutdown | shutdown(SOCKET, HOW)
Shuts down a SOCKET connection. If HOW is 0, further receives will be disallowed. If HOW is 1, further sends will be disallowed. If HOW is 2, then further sends and receives will be disallowed.
See shutdown(2). |
sin | sin(EXPR)
sin
Returns the sine of EXPR (expressed in radians). If EXPR is omitted, returns sine of $_. |
sleep | sleep(EXPR)
sleep EXPR
sleep
Causes program to sleep for EXPR seconds. If EXPR is omitted, program sleeps forever.
See sleep(3). |
socket | socket(SOCKET, DOMAIN, TYPE, PROTOCOL)
Opens a socket of a specified type and attaches it to filehandle, SOCKET.
See socket(2). |
socketpair | socketpair(SOCKET, SOCKET2, DOMAIN, TYPE, PROTOCOL)
Creates an unnamed pair of connect sockets in the specified domain of the specified type.
See socketpair(2). |
sort | sort(SUBROUTINE LIST)
sort(LIST)
sort SUBROUTINE LIST
sort LIST
Sorts the LIST and returns a sorted array. If SUBROUTINE is omitted, sorts in string comparison order. If SUBROUTINE is specified, gives the name of a subroutine that returns an integer less than, equal to, or greater than 0, depending on how the elements of the array are to be ordered. The two elements compared are passed (by reference) to the subroutine as $a and $b, rather than @_. SUBROUTINE cannot be recursive.
See Array Functions. |
splice | splice(ARRAY, OFFSET, LENGTH,LIST)
splice(ARRAY, OFFSET, LENGTH)
splice(ARRAY, OFFSET)
Removes elements designated starting with OFFSET and ending in LENGTH from an array and, if LIST is specified, replaces those elements removed with LIST. Returns the elements removed from the list. If LENGTH is not specified, everything from OFFSET to the end of ARRAY is removed. |
split | split(/PATTERN/, EXPR, LIMIT)
split(/PATTERN/, EXPR)
split(/PATTERN/)
split
Splits EXPR into an array of strings and returns them to an array. The PATTERN is the delimiter by which EXPR is separated. If PATTERN is omitted, whitespace is used as the delimiter. LIMIT specifies the number of fields to be split. |
sprintf | $string=sprintf(FORMAT, LIST)
Returns a string rather than sending output to STDOUT with the same formatting conventions as the printf function.
See printf(3). |
sqrt | sqrt(EXPR)
sqrt EXPR
Returns the square root of EXPR. If EXPR is omitted, the square root of $_ is returned. |
srand | srand(EXPR)
srand EXPR
srand
Sets the random seed for the rand function. If EXPR is omitted, the seed is the time function.
See rand(3). |
stat | stat(FILEHANDLE)
stat FILEHANDLE
stat(EXPR)
Returns a 13-element array consisting of file statistics for FILEHANDLE or file named as EXPR. The array consists of
the device the file inode number file mode number of hard links to the file user ID of owner group ID of owner raw device size of file file last access time file last modify time file last status change time preferred block size for filesystem I/O actual number of blocks allocated
See stat(2). |
study | study(SCALAR)
study SCALAR
study
Uses a linked-list mechanism to increase efficiency in searching for pattern matches that are to be repeated many times. Can study only one SCALAR at a time. If SCALAR is omitted, $_ is used. Most beneficial in loops where many short constant strings are being scanned. |
sub | sub NAME BLOCK
sub NAME
sub BLOCK
sub NAME PROTO BLOCK
sub NAME PROTO
sub PROTO BLOCK
The first two declare the existence of named subroutines and return no value. Without a block, sub NAME is a forward declaration. The sub BLOCK is used to create an anonymous subroutine. The last three are like the first three, except they allow prototypes to describe how the subroutine will be called. A prototype will notify the compiler that a subroutine definition will appear at some later time and can tell the compiler what type and how many arguments the subroutine expects. For example, sub foo ( $$@ ) declares that the subroutine foo will take three arguments, two scalars and an array. An error will occur if, for example, fewer than three arguments are passed. |
substr | substr(EXPR, OFFSET, LENGTH)
substr(EXPR, OFFSET)
Returns a substring after extracting the substring from EXPR starting at position OFFSET and, if LENGTH is specified, for that many characters from OFFSET. If OFFSET is negative, starts from the far end of the string. |
symlink | symlink(OLDFILE, NEWFILE)
Creates a symbolic link. NEWFILE is symbolically linked to OLDFILE. The files can reside on different partitions.
See symlink(2). |
syscall | syscall(LIST)
syscall LIST
Calls the system call specified as the first element in LIST, where the system call is preceded with &SYS_ as in &SYS_system call. The remaining items in LIST are passed as arguments to the system call. Requires syscall.ph. |
sysopen | sysopen( FILEHANDLE, FILENAME, MODE)
sysopen( FILEHANDLE, FILENAME, MODE, PERMS)
Opens FILENAME, using the underlying operating system's version of the open call, and assigns it to FILEHANDLE. The file modes are system dependent and can be found in the Fcntl library module. 0 means read-only, 1 means write-only, and 2 means read/write. If PERMS is omitted, the default is 0666.
See open(2). |
sysread | sysread(FILEHANDLE, SCALAR, LENGTH, OFFSET)
sysread(FILEHANDLE, SCALAR, LENGTH)
Reads LENGTH bytes into variable SCALAR from FILEHANDLE. Uses the read system call.
See read(2). |
sysseek | sysseek(FILEHANDLE, POSITION, WHENCE)
Sets FILEHANDLE's system position, using the syscall lseek function, bypassing standard I/O. The values of WHENCE are 0 to set the new position to POSITION, 1 to set it to the current position plus POSITION, and 2 to set it to EOF plus POSITION (often negative).
See lseek(2). |
system | system(LIST)
system LIST
Executes a shell command from a Perl script and returns. Like the exec function, except forks first, and the script waits until the command has been executed. Control then returns to script. The return value is the exit status of the program and can be obtained by dividing by 256 or right-shifting the lower 8 bits.
See system(3). |
syswrite | syswrite(FILEHANDLE, SCALAR, LENGTH, OFFSET)
syswrite(FILEHANDLE, SCALAR, LENGTH)
syswrite(FILEHANDLE, SCALAR)
Returns the number of bytes written to FILEHANDLE. Writes LENGTH bytes from variable SCALAR to FILEHANDLE, starting at position OFFSET, if OFFSET is specified. Uses the write system call.
See write(2). |
tell | tell(FILEHANDLE)
tell FILEHANDLE
tell
Returns the current file position, in bytes (starting at byte 0), for FILEHANDLE. Normally the returned value is given to the seek function in order to return to some position within the file.
See lseek(2). |
telldir | telldir(DIRHANDLE)
telldir DIRHANDLE
Returns the current position of the readdir function for the directory structure, DIRHANDLE.
See directory(3). |
tie | tie(VARIABLE, CLASSNAME, LIST)
Binds a VARIABLE to a package (CLASSNAME) that will use methods to provide the implementation for the variable. LIST consists of any additional arguments to be passed to the new method when constructing the object. Most commonly used with associative arrays to bind them to databases. The methods have predefined names to be placed within a package. The predefined methods will be called automatically when the tied variables are fetched, stored, destroyed, etc.
The package implementing an associative array provides the following methods:
TIEHASH $classname, LIST DESTROY $self FETCH $self, $key STORE $self, $key DELETE $self, $key EXISTS $self, $key FIRSTKEY $self NEXTKEY $self, $lastkey
Methods provided for an array are:
TIEARRAY $classname, LIST DESTROY $self FETCH $self, $subscript STORE $self, $subscript, $value
Methods provided for a scalar are:
TIESCALAR $classname, LIST DESTROY $self FETCH $self STORE $self, $value
|
| Example:
$object = tie %hash, Myhashclass
while($key, $value)=each (%hash){
print "$key, $value\n" # invokes the FETCH method
$object = tie @array, Myarrayclass
$array[0]=5 # invokes the STORE method
$object = tie $scalar, Myscalarclass
untie $scalar # invokes the DESTROY method
|
tied | tied VARIABLE
Returns a reference to the object that was previously bound with the tie function or undefined if VARIABLE is not tied to a package. |
time | time
Returns a 4-element array of non-leap-year seconds since January 1, 1970, UTC. Used with gmtime and localtime functions.
See ctime(3). |
times | times
Returns a 4-element array giving the user and system CPU times, in seconds, for the process and its children.
See times(3). |
tr | tr/SEARCHPATTERN/REPLACEMENT/[c][d][e]
y/SEARCHPATTERN/REPLACEMENT/[c][d][e]
Translates characters in SEARCHPATTERN to corresponding character in REPLACEMENT. Similar to UNIX tr command. |
truncate | truncate(FILEHANDLE, LENGTH)
truncate(EXPR, LENGTH)
Truncate FILEHANDLE or EXPR to a specified LENGTH.
See truncate(2). |
uc | uc EXPR
Returns EXPR (or $_ if no EXPR) in uppercase letters. Same as \U \E escape sequences. |
ucfirst | ucfirst EXPR
Returns the first character of EXPR (or $_ if no EXPR) in uppercase. Same as \u escape sequence. |
umask | umask(EXPR)
umask EXPR
umask
Sets the umask (file creation mask) for the process and returns the old umask. With EXPR omitted, returns the current umask value.
See umask(2). |
undef | undef(EXPR)
undef EXPR
undef
Undefines EXPR, an lvalue. Used on scalars, arrays, hashes, or subroutine names (&subroutine) to recover any storage associated with it. Always returns the undefined value. Can be used by itself when returning from a subroutine to determine if an error was made. |
unlink | unlink(LIST)
unlink LIST
unlink
Removes a LIST of files. Returns the number of files deleted. Without an argument, unlinks the value stored in $_.
See unlink(2). |
unpack | unpack(TEMPLATE, EXPR)
Unpacks a string representing a structure and expands it to an array value, returning the array value, using TEMPLATE to get the order and type of values. Reverse of pack.
See pack. |
unshift | unshift(LIST)
unshift
Prepends LIST to the beginning of an array. Returns the number of elements in the new array. |
untie | untie VARIABLE
Breaks the binding (unties) between a variable and the package it is tied to. Opposite of tie. |
use | use MODULE VERSION LIST
use MODULE LIST
use MODULE
use MODULE()
use pragma
A compiler directive that imports subroutines and variables from MODULE into the current package. VERSION is the current version number of Perl. LIST consists of specific names of the variables and subroutines the current package will import. Use empty parameters if you don't want to import anything into your namespace. The -m and -M flags can be used at the command line instead of use. Pragmas are a special kind of module that can affect the behavior for a block of statements at compile time. Three common pragmas are integer, subs, and strict. |
utime | utime(LIST)
utime LIST
Changes the access and modification times on a list of files.The first two elements of LIST are the numerical access and modification times. |
values | values(%ASSOC_ARRAY)
values ASSOC_ARRAY
Returns an array consisting of all the values in an associative array, ASSOC_ARRAY, in random order. |
vec | vec(EXPR, OFFSET, BITS)
Treats a string, EXPR, as a vector of unsigned integers. Returns the value of the element specified. OFFSET is the number of elements to skip over in order to find the one wanted, and BITS is the number of bits per element in the vector. BITS must be one of a power of 2 from 1 to 32; e.g., 1, 2, 4, 8, 16, or 32. |
wait | wait
Waits for the child process to terminate. Returns the pid of the deceased process and –1 if there are no child processes. The status value is returned in the $? variable.
See wait(2). |
waitpid | waitpid(PID, FLAGS)
Waits for a child process to terminate and returns true when the process dies or –1 if there are no child processes or if FLAGS specify nonblocking and the process hasn't died. $? gets the status of the dead process. Requires sys/wait.ph.
See wait(2). |
wantarray | wantarray
Returns true if the context of the currently running subroutine wants an array value; i.e., the returned value from the subroutine will be assigned to an array. Returns false if looking for a scalar. Example: return wantarray ? () : undef |
warn | warn(LIST)
warn LIST
Sends a message to STDERR, like the die function, but doesn't exit the program. |
write | write(FILEHANDLE)
write FILEHANDLE
write
Writes a formatted record to FILEHANDLE or currently selected FILEHANDLE (see select); i.e., when called, invokes the format (picture line) for the FILEHANDLE, with no arguments. Goes either to STDOUT or to the FILEHANDLE currently selected by the select call. Has nothing to do with the write(2) system call.
See syswrite. |
y | y/SEARCHPATTERN/REPLACEMENT/[c][d][e]
Translates characters in SEARCHPATTERN to corresponding characters in REPLACEMENT. Also known as tr and similar to UNIX tr command or sed y command. |