Perl-Sensitive Sunglasses | |
PerlMonks |
Re: Trimming whitespaces methodsby Anonymous Monk |
on Jun 30, 2008 at 14:18 UTC ( [id://694744]=note: print w/replies, xml ) | Need Help?? |
If you do not want to use the existing (and strongly recommended) utilities noted in other posts, I would use the expression s{ \A \s+ | \s+ \z }{}xmsg for @array;
Note that $_ is implicitly bound to the regex and so there is no need to use the expression $_ =~ s///. To trim the values of a hash, use an expression like s{ \A \s+ | \s+ \z }{}xmsg for values %hash; It is not clear to me what you mean by trimming the 'keys' of a hash: altering a hash key (which is a string) creates a different key.
In Section
Seekers of Perl Wisdom
|
|