5.18. String functions

  • length STRING - number of characters

  • lc STRING - lower case

  • uc STRING - upper case

  • index STRING, SUBSTRING - the location of a substring given its content

Example 5-13. examples/scalars/string_functions.pl

#!/usr/bin/perl
use strict;
use warnings; 

my $s = "The black cat jumped from the green tree";

print index $s, "ac";                         # 6
print "\n";

print index $s, "e";                          # 2
print "\n";
print index $s, "e", 3;                       # 18
print "\n";

print index $s, "dog";                        # -1
print "\n";

print rindex $s, "e";                         # 39
print "\n";
print rindex $s, "e", 38;                     # 38
print "\n";
print rindex $s, "e", 37;                     # 33
print "\n";

If you are interested in on-site trainings by the author, please contact me directly.

Online courses:

Would you like to get
updated when I publish
the next article?

Follow me:

Google Plus Twitter RSS feed