|
|
Listing C.14 contains an assortment of statements that remove white space from a text string.
Listing C.14 removeWhiteSpace1.pl
my($currentLine) = "\tline with spaces \n"; # remove all tabs $currentLine =~ s/\t//g; # remove all spaces $currentLine =~ s/ //g; # remove all white space $currentLine =~ s/\s+//g; # remove all leading white space $currentLine =~ s/^\s+//; # remove all trailing white space $currentLine =~ s/\s+$//; # remove trailing line feed $currentLine =~ s/\n$//; # remove all line feeds $currentLine =~ s/\n//g; # print the line print "final line = $currentLine\n";
You can launch the Perl script removeWhiteSpace1.pl in Listing C.14 from the command line as follows:
perl -w removeWhiteSpace1.pl
and the output is as follows:
final line = linewithspaces
|
|