Writing to Files in Perl

   



Removing White Space in Text Strings

Listing C.14 contains an assortment of statements that remove white space from a text string.

Listing C.14 removeWhiteSpace1.pl

start example
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"; 
end example

Remarks

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



   



Fundamentals of SVG Programming. Concepts to Source Code
Fundamentals of SVG Programming: Concepts to Source Code (Graphics Series)
ISBN: 1584502983
EAN: 2147483647
Year: 2003
Pages: 362

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net