Perl Cheat Sheet Page 13

ADVERTISEMENT

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
into a single string with fields separated by
LIST
the value of
EXPR
, and returns the string.
keys
%
HASH
Returns an array of all the keys of the named hash.
map EXPR, LIST
map BLOCK LIST
Evaluates
or
for each element of the
, locally setting $_
EXPR
BLOCK
LIST
to refer to the element. Modifying $_ will modify the corresponding
element from
. Returns the list of results.
LIST
[ @
]
pop
ARRAY
Pops off and returns the last value of the array. If @
is omitted, pops
ARRAY
@ARGV in main and @_ in subroutines.
push
ARRAY, LIST
@
Pushes the values of the 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
with bytes reversed.
LIST
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 @
is omitted, shifts @ARGV in main
ARRAY
and @_ in subroutines.
sort
[
SUBROUTINE
]
LIST
Sorts the
LIST
and returns the sorted array value. If
SUBROUTINE
is
specified, gives the name of a subroutine that returns less than zero, zero, or
greater than zero, depending on how the elements of the array, available to
the routine as package global variables $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
(if specified). Returns the elements removed.
LIST
y [
[
[
] ] ]
split
PATTERN
, EXPR
, LIMIT
Splits a string into an array of strings, and returns it. If
is specified,
LIMIT
splits into at most that number of fields. If
PATTERN
is omitted, splits on
whitespace (after skipping any leading whitespace). If not in array context:
returns number of fields and splits to @_ .
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.
13

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education