#!/usr/bin/perl -w ####################################################### # class7_05_subst_count_to_file # # 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 ####################################################### STDOUT = "my_results"; $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!' s/perl/PERL!/g; printf "VERSION AFTER SUBST:<%s>\n", $_; } print "\nNumber of lines with trailing whitespace removed: $num_changed\n\n"; # end of class7_04_subst_count