in reply to removing redundantwhitespace
use strict; use warnings; my $string = qq{one two \n\n three\t\t\n four five\n\n\n\t six \n\n}; my $newString = join qq{\n}, map { s{^\s+}{}; s{\s+$}{}; s{\s+}{ }g; $_; } split m{\n+}, $string; print qq{->$newString<-\n};
The output.
->one two three four five six<-
I hope this is useful.
Cheers,
JohnGG
Update: Just realised that the third substitution in the map should be global. Corrected.
|
|---|