Built-in Function Overview


Beginning | Previous | Next

People's Choice Award Winning Functions

Below is a list of personal favorite functions (and reserved words) that I have found to be popular around campus.

File and Directory Operations

chmod (list)
just like in UNIX
chown (list)
just like in UNIX
mkdir (dir, mode)
just like in UNIX
print [filehandle] [list]
print stuff to a filehandle, if filehandle is omitted, STDOUT is assumes
printf [filehandle] [list]
like print(), but can do formatted prints using C-like printf() codes
rename (old_name, new_name)
rename a file
rmdir (dir)
remove and empty directory
seek (filehandle, position, whence)
go a file pointer to a particular location within an open file
stat (filename)
get file info similar to C's runtime library, ex, $file_size = (stat ($filename))[7];
unlink (list)
delete files, returns the number of files deleted

Sting Functions

chomp (list)
remove newline from end of each element
chop (list)
remove last character from each element
eval (expr)
expr is parsed and executed as if it were a Perl program. If there is a syntax or runtime error, an undefined string is returned by eval() and $@ is set to the error message between {}
length (expr)
return length in characters
substr (expr, offset [, len])
extract a substring of length len out of expr and return it

Array Functions

grep (expr, list)
expr can be a regex
join (expr, list)
returns list joined by expr
keys (%hash)
return the keys in a hash in no particular order
pop (@array)
pops off and returns the last value of the array
push (@array, list)
pushes the value of list onto the end of the erray
shift (@array)
shifts the first value of the array off and returns it, shortening the array by 1 and moving everything down
sort (list)
sorts the list and returns it
splice (@array, offset [, length [, list] ])
removes the elements of @array designated by offset and length and replaces them with list, and returns elements removed
split ([pattern [, expr [, limit ] ] ])
splits a string into an array of strings and returns it. If limit is specified, splits into at most that number. If pattern is omitted, splits at the whitespace. If not in an array context, returns number of fields and splits to @_.

Subroutines, Packages and Modules

package name
designates the remainder of the current block as a package
require expr
if expr is numeric, requires Perl to be at least that version (use this if you are using functionality of a specific version, eg, references in perl 5), otherwise expr must be the name of a file
return expr
returns from a subroutine with the value specified
use name [ [version] list]
imports semantics from the named module into the current package

System Interaction

chdir [list]
changes the working directory Note: This only works in the context of the script. Once the script exits, you are in the directory you started from.
die [list]
prints values of list to STDERR
exit [expr]
exits immediately with the value of expr
fork
does a fork(2) system call and returns the PID of the child to the parent and zero to the child process
kill [list]
sends a signal to a list of processes, the first element of the list must be the signal to send
sleep [expr]
causes the program to sleep for expr seconds
warn [list]
prints a message to STDERR like die() but does not exit

Miscellaneous

defined (expr)
test whether the lvalue expr has an actual value

Networking and UNIX Specific Functions

There are many other functions, too numerous to mention here, that can be learned once you get the general flavor of how the language works.

Beginning | Previous | Next
Last Modified: $Date: 1997/05/02 07:17:35 $