Please send questions to
st10@humboldt.edu .
#!/usr/bin/perl -w
#######################################################
# lect04_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: 9-14-04
#######################################################
# 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 lect04_subst_whitespace