Perl Cheat Sheet Page 12

ADVERTISEMENT

13. String functions
y
chomp LIST
Removes line endings from all elements of the list; returns the (total)
number of characters removed.
y
chop LIST
Chops off the last character on all elements of the list; returns the last
chopped character.
crypt PLAINTEXT, SALT
Encrypts a string.
y
eval EXPR
is parsed and executed as if it were a Perl program. The value
EXPR
returned is the value of the last expression evaluated. If there is a syntax
error or runtime error, undefis returned by
, and $@ is set to the error
eval
message. See also
in section ‘Miscellaneous’.
eval
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’).
y
length EXPR
Returns the length in characters of
.
EXPR
y
lc EXPR
Returns a lower case version of
EXPR
.
y
lcfirst EXPR
Returns
with the first character in lower case.
EXPR
y
quotemeta EXPR
Returns
EXPR
with all regexp meta-characters quoted.
[
]
rindex STR, SUBSTR
, OFFSET
Returns the position of the last
in
at or before
.
SUBSTR
STR
OFFSET
[
]
substr EXPR, OFFSET
, LEN
Extracts a substring out of
EXPR
and returns it. If
OFFSET
is negative,
counts from the end of the string. If
is negative, leaves that many
LEN
characters off the end of the string. May be assigned to.
y
uc EXPR
Returns an upper case version of
EXPR
.
y
ucfirst EXPR
Returns
with the first character in upper case.
EXPR
14. Array and hash functions
delete
HASH
KEY
$
{
}
Deletes the specified value from the specified hash. Returns the deleted
value (unless
is
d to a package that does not support this).
HASH
tie
each
%
HASH
Returns a 2-element array consisting of the key and value for the next value
of the hash. After all values of the hash have been returned, an empty list is
returned. The next call to
after that will start iterating again.
each
y
exists EXPR
Checks whether the specified hash key exists in its hash array.
12

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education