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

#######################################################
# lect04_subst_count
#
# playing with the s/// operator, showing it returns
# true when substitution done to count the number
# of lines where substitution has occurred
#
# modified by Sharon Tuttle from "Learning Perl",
#    by Schartz and Phoenix
#
# last modified: 9-14-04
#######################################################

$num_changed = 0;

while (<>)
{
    chomp;

    # let's keep count of how many lines actually have substitutions
    # made to them (let's replace trailing white space with nothing)
    if (s/\s+$//)
    {             
        $num_changed++;
    }

    #   substitute the EVERY 'perl' in each line with 'PERL!'
    #   (I'm NOT counting these changes, note!!!)i
    s/perl/PERL!/g;

    print "<$_>\n";
}

print "\nNumber of lines with trailing whitespace removed:
$num_changed\n\n";


# end of lect04_subst_count