Friday, November 4, 2011

Function - Substring (substr)

 Substring (substr)
The substring function is a way to get a portion of a string value, rather than using the entire value.
The value can then be used in a loop or a conditional statement, or just for its own purposes.
For this one, you will probably want the general form of the function first.
The function is usually set to a variable so that the variable contains the value of the substring:


$ cat substr.pl
#!/usr/bin/perl
use strict;
my $test="sriram";
my $new = substr($test,3,5);
print "the new value of substring is $new\n";

sriram@ubuntu:~/perl$ ./substr.pl
the new value of substring is ram
sriram@ubuntu:~/perl$

No comments:

Post a Comment