Chapter 5. Function Reference
This chapter gives a brief description of Perl's
built-in functions. Each description gives the syntax of the
function, with the types and order of its arguments.
Required arguments are shown in italics, separated by commas. If an
argument must be a specific variable type, that
variable's identifier will be used (e.g., a percent
sign for a hash,
%hash). Optional
arguments are placed in brackets. Do not use the brackets in function
calls unless you really want to use an anonymous hash reference.
There are different ways to use a built-in function. For starters,
any argument that requires a scalar value can be made up of any
expression that returns one. For example, you can obtain the square
root of the first value in an array:
$root = sqrt (shift @numbers);
shift removes the first element of
@numbers and returns it to be used by
sqrt.
Many functions take a list of scalars for arguments. Any array
variable or other expression that returns a list can be used for all
or part of the arguments. For example:
chmod (split /,/ FILELIST>); # An expression returns a list
chmod 0755, @executables; # Array used for part of arguments
In the first line, the split expression reads a
string from a filehandle and splits it into a list. The list provides
proper arguments for chmod. The second line uses
an array that contains a list of filenames for
chmod to act upon.
Parentheses are not
required around a function's arguments. However,
without parentheses, functions are viewed as operators in an
expression (the same is true of predeclared subroutines). If you use
a function in a complex expression, you may want to use parentheses
for clarity. See Chapter 4, "The Perl Language" for more about
precedence in Perl expressions.
5.1. Perl Functions by Category
Here are
Perl's functions and function-like keywords,
arranged by category. Note that some functions appear in more than
one category.
- Scalar manipulation
-
chomp, chop,
chr, crypt,
hex, index,
lc, lcfirst,
length, oct,
ord, pack,
q//, qq//,
reverse, rindex,
sprintf, substr,
tr///, uc,
ucfirst, y///
- Regular expressions and pattern matching
-
m//,
pos, qr//,
quotemeta, s///,
split, study
- Numeric functions
-
abs,
atan2, cos,
exp, hex,
int, log,
oct, rand,
sin, sqrt,
srand
- Array processing
-
pop,
push, shift,
splice, unshift
- List processing
-
grep,
join, map,
qw//, reverse,
sort, unpack
- Hash processing
-
delete,
each, exists,
keys, values
- Input and output
-
binmode,
close, closedir,
dbmclose, dbmopen,
die, eof,
fileno, flock,
format, getc,
print, printf,
read, readdir,
rewinddir, seek,
seekdir, select,
syscall, sysread,
sysseek, syswrite,
tell, telldir,
truncate, warn,
write
- Fixed-length data and records
-
pack,
read, syscall,
sysread, syswrite,
unpack, vec
- Filehandles, files, and directories
-
chdir,
chmod, chown,
chroot, fcntl,
glob, ioctl,
link, lstat,
mkdir, open,
opendir, readlink,
rename, rmdir,
stat, symlink,
sysopen, umask,
unlink, utime
- Flow of program control
-
caller,
continue, die,
do, dump,
eval, exit,
goto, last,
next, redo,
return, sub,
wantarray
- Scoping
-
caller,
import, local,
my, package,
use
- Miscellaneous
-
defined, dump,
eval, formline,
local, my,
prototype, reset,
scalar, undef,
wantarray
- Processes and process groups
-
alarm, exec,
fork, getpgrp,
getppid, getpriority,
kill, pipe,
qx//, setpgrp,
setpriority, sleep,
system, times,
wait, waitpid
- Library modules
-
do,
import, no,
package, require,
use
- Classes and objects
-
bless,
dbmclose, dbmopen,
package, ref,
tie, tied,
untie, use
- Low-level socket access
-
accept,
bind, connect,
getpeername, getsockname,
getsockopt, listen,
recv, send,
setsockopt, shutdown,
socket, socketpair
- System V interprocess communication
-
msgctl,
msgget, msgrcv,
msgsnd, semctl,
semget, semop,
shmctl, shmget,
shmread, shmwrite
- Fetching user and group information
-
endgrent,
endhostent, endnetent,
endpwent, getgrent,
getgrgid, getgrnam,
get-login,
getpwent, getpwnam,
getpwuid, setgrent,
setpwent
- Fetching network information
-
endprotoent,
endservent, gethostbyaddr,
gethostbyname, gethostent,
getnet-byaddr,
getnetbyname, getnetent,
getprotobyname,
getprotobynumber, getprotoent,
getservbyname, getservbyport,
getservent, sethostent,
setnet-ent,
setprotoent, setservent
- Time
-
gmtime,
localtime, time,
times
| | | 4.13. Pod | | 5.2 Perl Functions in Alphabetical Order |
Copyright © 2002 O'Reilly & Associates. All rights reserved.
|
|