sftriman wrote:
1ST PLACE - THE WINNER: 5.0s average on 5 runs
# Limitation - pointer
sub fixsp5 {
${$_[0]}=~tr/ \t\n\r\f/ /s;
${$_[0]}=~s/\A //;
${$_[0]}=~s/ \z//;
}
Just decide to change in-place, based on the defined-ness of wantarray.
sub trim {
no warnings 'uninitialized';
if ( defined wantarray ) {
# need to return scalar / list
my @values= @_;
s#^\s+##s, s#\s+$##s foreach @values;
return wantarray ? @values : $values[0];
}
# need to change in-place
s#^\s+##s, s#\s+$##s foreach @_;
return;
} #trim
--
Ruud
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/