October 7th, 2009, 11:07 AM
Join Date: Feb 2008
Time spent in forums: 3 h 1 m 10 sec
Reputation Power: 0
Remove white space and carriage returns, line feeds
I have a perl script that reads a $message variable which is typed in by the user.
We was trying to remove all white spaces that could be in front, all white spaced at the end, extra spaced inbetween words (For example 2 spaces or more between works would be reduced to 1 space) and to remove any carriage returns or line feeds.
I am very new to Perl and have been unable to figure this out.
What I had so far was this....
$message =~ s/[\n\r\s]+//g;
But this is removing all white space even between words.
This is the input it was given...
ottocat:/lcl/apps/esm/bin>postEvent.pl -s 60 -m ' MESSAGE GOES HERE ' -g 'INFR_Apps' -i 'ISOC INSTRUCTIONS GO HERE' -t -p 'Test_Program' Testing
The -m is the message text.
However the output results in...
It should say "MESSAGE GOES HERE"
Could somebody show me the correct format to use to remove....
1.) Front white spaces
2.) Carriage returns
3.) Line feeds
4.) End white spaces
5.) Any extra white spaces between words.
So for example if it said...
"This is a test."
It would remove the extra white space between "is" and "a".