substr

substrEXPR,OFFSET,LENGTH,REPLACEMENTsubstrEXPR,OFFSET,LENGTHsubstrEXPR,OFFSET
This function extracts a substring out of the string given by
EXPR and returns it. The substring is
extracted starting at OFFSET characters from
the front of the string. If OFFSET is
negative, the substring starts that far from the end of the string
instead. If LENGTH is omitted, everything to
the end of the string is returned. If LENGTH
is negative, the length is calculated to leave that many characters off
the end of the string. Otherwise, LENGTH
indicates the length of the substring to extract, which is sort of what
you’d expect.
Notice we said characters, by which we mean codepoints, not bytes
or graphemes. For bytes, encode into UTF-8 first and try again. For
graphemes, use the substr method from
the CPAN Unicode::GCString module.
You may use substr as an lvalue
(something to assign to), in which case EXPR must also be a legal lvalue. If you assign something shorter than the length of your substring, the string will shrink, and if you assign something longer than the length, the string will grow to accommodate it. To keep the string the same length, you may need to pad or chop your value ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access