Cartoon Edmund

Home

Calendar

Contact

Knight Vision

Sitemap



Edmund J. Sutcliffe
Thoughtful Solutions, Creatively Implemented and Communicated

Edmund's Perl Quick Reference - 1 2 3 4 5 6 7 8 9
Click here for a printable version of this page.

String Functions

chomp LIST†
Removes line endings from all elements of the list; returns the (total) number of characters removed.
chop LIST†
Chops off the last character on all elements of the list; returns the last chopped character.
crypt PLAINTEXT, SALT
Encrypts a string.
eval EXPR†
EXPR is parsed and executed as if it were a Perl program. The value returned is the value of the last expression evaluated. If there is a syntax error or runtime error, an undefined string is returned by eval, and $@ is set to the error message. See also eval in section Miscellaneous.
index STR, SUBSTR [ , OFFSET ]
Returns the position of SUBSTR in STR at or after OFFSET. If the substring is not found, returns -1 (but see $[ in section Special Variables).
length EXPR†
Returns the length in characters of the value of EXPR.
lc EXPR
Returns a lowercase version of EXPR.
lcfirst EXPR
Returns EXPR with the first character lowercase.
quotemeta EXPR
Returns EXPR with all regular expression metacharacters quoted.
rindex STR, SUBSTR [ , OFFSET ]
Returns the position of the last SUBSTR in STR at or before OFFSET.
substr EXPR, OFFSET [ , LEN ]
Extracts a substring of length LEN out of EXPR and returns it. If OFFSET is negative, counts from the end of the string. May be assigned to.
uc EXPR
Returns an uppercased version of EXPR.
ucfirst EXPR
Returns EXPR with the first character uppercased.

Array and List Functions

delete $HASH{KEY}
Deletes the specified value from the specified hash. Returns the deleted value unless HASH is tied to a package that does not support this.
each %HASH
Returns a 2-element array consisting of the key and value for the next value of the hash. Entries are returned in an apparently random order. After all values of the hash have been returned, a null array is returned. The next call to each after that will start iterating again.
exists EXPR†
Checks if the specified hash key exists in its hash array.
grep EXPR, LIST
grep BLOCK LIST
Evaluates EXPR or BLOCK for each element of the LIST, locally setting $_ to refer to the element. Modifying $_ will modify the corresponding element from LIST. Returns the array of elements from LIST for which EXPR returned true.
join EXPR, LIST
Joins the separate strings of LIST into a single string with fields separated by the value of EXPR, and returns the string.
keys %HASH
Returns an array with all of the keys of the named hash.
map EXPR, LIST
map BLOCK LIST
Evaluates EXPR or BLOCK for each element of the LIST, locally setting $_ to refer to the element. Modifying $_ will modify the corresponding element from LIST. Returns the list of results.
pop @ARRAY
Pops off and returns the last value of the array.
push @ARRAY, LIST
Pushes the values of LIST onto the end of the array.
reverse LIST
In array context, returns the LIST in reverse order. In scalar context: returns the first element of LIST with bytes reversed.
scalar @ARRAY
Returns the number of elements in the array.
scalar %HASH
Returns a true value if the hash has elements defined.
shift [ @ARRAY ]
Shifts the first value of the array off and returns it, shortening the array by 1 and moving everything down. If @ARRAY is omitted, shifts @ARGV in main and @_ in subroutines.
sort [ SUBROUTINE ] LIST
Sorts the LIST and returns the sorted array value. SUBROUTINE, if specified, must return less than zero, zero, or greater than zero, depending on how the elements of the array (available to the routine as $a and $b) are to be ordered. SUBROUTINE may be the name of a user-defined routine, or a BLOCK.
splice @ARRAY, OFFSET [ , LENGTH [ , LIST ] ]
Removes the elements of @ARRAY designated by OFFSET and LENGTH, and replaces them with LIST (if specified). Returns the 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 of fields. If PATTERN is also omitted, splits at the whitespace. If not in array context, returns number of fields and splits to @_. See also Search and Replace Functions.
unshift @ARRAY, LIST
Prepends list to the front of the array, and returns the number of elements in the new array.
values %HASH
Returns a normal array consisting of all the values of the named hash.

 


Cartoon Edmund

Quick Ref

Tech Tips

Travel Tips

Tech News

Images