in reply to Sort path strings by component count.
And I replaced it with:my $word_count = int(split(' ', $string));
My first thought was that using "split" to count was inelegant, but there were two problems with getting away from it in this case.my $word_count = scalar(my @words = split(' ', $string));
The other problem was that it's not so simple to precisely match split's ' ' special case, which ignores any leading or trailing spaces.$string =~ s/(\s+)/$1/g;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sort path strings by component count.
by Roy Johnson (Monsignor) on Feb 27, 2006 at 15:57 UTC |