in reply to Trimming whitespaces methods
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///.
Furthermore, the use of \s* in the expression you originally posted means that a substitution will be done in every string, since every string has zero or more whitespace at its beginning and end.
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.
|
---|