Get the Length of a Word or String in Perl
To get the length of a word or string in Perl:
$dr="This is a short sentence";
$ft=length($dr);
print $ft;
Which prints:
24
-We create a variable and name it $dr because we are lazy typers.
-We use Perl's built-in
length function on our variable $dr and store it in our newly created variable $ft.
-We
print $ft.
We could have also done:
$ft=length("Hiyas");
print $ft;
Which prints:
5
-This time we just put the word/sentence right into the length function.
-Since our word/sentence is not a variable, we must enclose it in quotation marks.
Copy and Paste Perl Code:
#!/usr/bin/perl
print "Content-type:text/html\n\n";
$dr="This is a short sentence";
$ft=length($dr);
print "$ft ";
$ft=length("Hiyas");
print $ft;
exit;
Resources:
Use the Perl PRINT FUNCTION
Finding the Length (Index Numbers) of an Array in Perl