Instead of capturing and replacing all with the captured string, I'd just remove whitespace at the beginning and end of the string:
s/^\s+|\s+$//g;
one way to trim keys and values of a hash:
%hash = map { $v = $hash{$_}; s/^\s+|\s+$//g for $v,$_; $_,$v } keys % +hash; # another way which doesn't copy the entire has, just the keys for my $key (keys %hash) { my $value = delete $hash{$key}; for ($key, $value) { s/^\s+|\s+$//g; } $hash{$key} = $value; }
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
In reply to Re: Trimming whitespaces methods
by shmem
in thread Trimming whitespaces methods
by harishnuti
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |