Nasser Heidari

2010-03-05

Perl: substr

Filed under: Miscellaneous — Nasser Heidari @ 13:59

Extracts a substring out of EXPR and returns it.

* substr EXPR,OFFSET,LENGTH,REPLACEMENT
* substr EXPR,OFFSET,LENGTH
* substr EXPR,OFFSET

e.g:
1. my $s = “The black cat climbed the green tree”;
2. my $color = substr $s, 4, 5; # => black
3. my $middle = substr $s, 4, -11; # => black cat climbed the
4. my $end = substr $s, 14; # => climbed the green tree
5. my $tail = substr $s, -4; # => tree
6. my $z = substr $s, -4, 2; # => tr

Original Document => http://perldoc.perl.org/functions/substr.html

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: