#!/usr/bin/perl -w ####################################################### # class7_03_subst_whitespace # # playing with the s/// operator with /g modifier (s///g) # some more --- ridding values of excess whitespace... # # modified by Sharon Tuttle from "Learning Perl", # by Schartz and Phoenix # # last modified: 5-2-03 ####################################################### # here is a line with TOO much white space... $_ = "\tHello, there! \t \t How are you? \t\t "; printf "\$_ starts as:<%s>\n", $_; # this SHOULD replace *consecutive* whitespace characters with a single # space: s/\s+/ /g; printf "\$_ is now: <%s>\n", $_; # this SHOULD replace any whitespace at the BEGINNING of $_ with # nothing (that is, REMOVE it): s/^\s+//g; printf "\$_ is now: <%s>\n", $_; # this SHOULD replace any whitespace at the END of $_ with nothing # (that is, remove it): s/\s+$//; printf "\$_ is now: <%s>\n", $_; # end of class7_03_subst_whitespace