Please send questions to st10@humboldt.edu .
#!/usr/bin/perl -w

###########################################################
# lect07_string_stuff
#
# some quick'n'sleazy examples involving the index and
#    substr functions
#
# modified by Sharon Tuttle from "Learning Perl",
#    by Schartz and Phoenix
#
# last modified: 10-7-04
#######################################################

my $big = "The rain in Spain stays mainly in the plain";
my $small = "ain";

# $where is set to the position of the first instance of
#   $small in $big (starting with 0 !)

my $where = index($big, $small);

print "$small first occurs in $big at position $where\n";

# index returns -1 if small ISN'T in big

$where = index($big, "George");

print "\$where: $where\n";

# third argument: where to START searching!

$where = index($big, $small, 6);

print "\$where: $where\n";

# rindex: search from the RIGHT

$where = rindex($big, $small);

print "\$where: $where\n";

# substr lets you grab a substring from a given position

print substr($big, $where, 3) . "\n";
print substr($big, -4, 5) . "\n";

substr($big, 0, 8) = "Blizzards";

print "$big\n";

substr($big, 20) =~ s/ain/ane/g;

print "$big\n";