in reply to Re: Deleting intermediate whitespaces, but leaving one behind each word
in thread Deleting intermediate whitespaces, but leaving one behind each word

Note that  split / +/, $string doesn't handle leading whitespace gracefully:

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $CPU = ' Intel(R) Xeon(R) CPU X5660 2.80GHz '; dd $CPU; ;; my @CPU_SPLIT = split / +/, $CPU; dd \@CPU_SPLIT; ;; my $t = join ' ', @CPU_SPLIT; dd $t; " " Intel(R) Xeon(R) CPU X5660 2.80GHz " ["", "Intel(R)", "Xeon(R)", "CPU", "X5660", "2.80GHz"] " Intel(R) Xeon(R) CPU X5660 2.80GHz"
Here, the special-case  ' ' split pattern is better (if you're going to split/join):
c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $CPU = ' Intel(R) Xeon(R) CPU X5660 2.80GHz '; dd $CPU; ;; my @CPU_SPLIT = split ' ', $CPU; dd \@CPU_SPLIT; ;; my $t = join ' ', @CPU_SPLIT; dd $t; " " Intel(R) Xeon(R) CPU X5660 2.80GHz " ["Intel(R)", "Xeon(R)", "CPU", "X5660", "2.80GHz"] "Intel(R) Xeon(R) CPU X5660 2.80GHz"
(Dealing with general whitespace was exactly why  ' ' was special-cased.)


Give a man a fish:  <%-{-{-{-<