Gunnar Hjalmarsson wrote:
sub trim {
for ( $_[0] ) {
s/^\s+//;
s/\s+$//;
}
}
The following respects the environment better. :)
sub trim {
if ( defined wantarray() ) {
my @_s = @_; # copy
s/\s+$//, s/^\s+//
for grep defined(), @_s;
return wantarray() ? @_s : $_s[0];
}
s/\s+$//, s/^\s+//
for grep defined(), @_; # in place
return;
}
--
Ruud
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/
