#!/usr/bin/perl -w

#######################################################
# class7_04_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: 5-2-03
#######################################################

$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 class7_04_subst_count