in reply to Deleting intermediate whitespaces, but leaving one behind each word
the solutions using a simple regex suggested by Athanasius and haukex are great and definitely better than any solution using split and join (and I would have suggested exactly the same solution as haukex if he had not done it before).
However, I feel it might be useful for you to see how your original solution could be improved:
use strict; use warnings; my @CPU_SPLIT = split /\s+/, $CPU; # split the string on one or mo +re spaces # ~ s\ //g; # this line does not make any s +ense to me, commented out. my $result = join ' ', @CPU_SPLIT; # join can operate directly on +an array, no need to list the indices
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Deleting intermediate whitespaces, but leaving one behind each word
by Eily (Monsignor) on Dec 05, 2017 at 09:21 UTC | |
by Laurent_R (Canon) on Dec 05, 2017 at 11:10 UTC |