Built-In Routines



next up previous
Next: UNIX-type Utility Routines Up: Built-In RoutinesC Previous: Built-In RoutinesC

Built-In Routines

chop expr
Chop off the last character of a string and return the character. This might not seem like a very interesting thing to do until you understand Perl file I/O. Upon reading a line of input into a variable, Perl preserves the newline (\n). Usually, you don't need the newline so you probably want to chop it off.
defined expr
Determine whether or not the named variable really exists or not. This function will return true if the named variable has a value and is not simply undefined.
die expr
Utter a final message and pass away. This function will print out a string argument and then cause the script to terminate. It is used most often when some kind of fatal error occurs.
each array
Return the key-value pairs of an associative array in an iterative manner.
join expr,array
Joins the separate strings of array into a single string with fields separated by the value of expr, and returns the string.
pop array
Pop off the top element off the named array and shorten the array by one.
print expr
Print out the arguments. More on the print function later.
push array,list
Treat array as a stack and push the values of list on to the stack. Has the effect of lengthening the array.
shift
Shifts the first value of the array off and returns it, shortening the array by 1 and moving everything down. Shift() and unshift() do the same thing to the left end of an array that push() and pop() do to the right end.
split(/pattern/,expr,limit
) Splits a string into an array of strings and returns it. The pattern is treated as a delimiter separating the fields. A common use of this function is to split up lines of the UNIX /etc/passwd file into its component fields. This is similar awk's functionality only more versatile.
substr expr,offset,len
Extract a substring out of expr and returns it.



next up previous
Next: UNIX-type Utility Routines Up: Built-In RoutinesC Previous: Built-In RoutinesC