sub trim {
@_ = @_ ? @_ : $_ if defined wantarray; # disconnect aliases in non-void context
for (@_ ? @_ : $_) { s/\A\s+//; s/\s+\z// }
return wantarray ? @_ : "@_";
}
####
foreach (@args) {
<...>;
trim;
<...>;
}
####
foreach (@args) {
my @b;
<...>
@b = ();
trim(@b); # silently the same as trim($_) since @b has no elements
<...>;
}
####
sub trim {
if ( !@_ && !defined(wantarray) ) { carp 'Useless use of trim with no arguments in void return context (did you mean "trim($_)"?)'; return; }
if ( !@_ ) { carp "Useless use of trim with no arguments"; return; }
@_ = @_ if defined wantarray;
for (@_) { s/\A\s+//; s/\s+\z// }
return wantarray ? @_ : "@_";
}