Chapter 20. String Functions

chomp list†

Removes $/ 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 (irreversibly).

eval expr†

Parses and executes expr 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, undef is returned by eval, and $@ is set to the error message. See also eval.

index str, substr [ , offset ]

Returns the position of substr in str at or after offset. If the substring is not found, returns –1.

lc expr†

Returns a lowercase version of expr. See also \L.

lcfirst expr†

Returns expr with its first character in lowercase. See also \l.

length expr†

Returns the length in characters of expr.

quotemeta expr†

Returns expr with all regular expression metacharacters quoted. See also \Q.

rindex str, substr [ , offset ]

Returns the position of the last substr in str at or before offset. If the substring is not found, returns –1.

substr expr, offset [ , len [ , newtext ] ]

Extracts a substring of length len starting at offset out of expr and returns it. If offset is negative, counts from the end of the string. If len is negative, leaves that many characters off the end of the string. Replaces the substring with newtext if specified. Otherwise, may be assigned to.

uc expr†

Returns an uppercase version of expr. See also ...

Get Perl Pocket Reference, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.