Perl in a Nutshell

Perl in a NutshellSearch this book
Previous: Reference: subChapter 5
Function Reference
Next: Reference: symlink
 

substr

substr string, pos, [n, replacement]

Extracts and returns a substring n characters long, starting at character position pos, from a given string. If pos is negative, the substring starts that far from the end of the string instead. If n is omitted, everything to the end of the string is returned. If n is negative, the length is calculated to leave that many characters off the end of the string.

You can use substr() as an lvalue - replacing the delimited substring with a new string - if string is given as an lvalue. You can also specify a replacement string in the fourth parameter to replace the substring. The original extracted substring is still returned.


Previous: Reference: subPerl in a NutshellNext: Reference: symlink
Reference: subBook IndexReference: symlink

Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.