in reply to Strip spaces in hash
You can't change a hash key, so you're better off just doing your stripping when you build the first hash. It's not a one-liner solution, but I often use bits of code like these:
# If I need cleanup only in one place, or want a special cleanup: my ($key, $value) = map { s/\s+$//; s/^\s+//; $_ } ($orig_key, $orig_v +alue); # If I need to clean strings frequently in a program: my ($key, $value) = map { clean_string($_) } ($orig_key, $orig_value); sub clean_string { my $orig = shift; $orig =~ s/^\s+//; $orig =~ s/\s+$//; # ... other cleanup you want ... $orig; } # Alternative: my ($key, $value) = clean_strings($orig_key, $orig_value); sub clean_strings { my @a = map { clean_string($_) } @_; return @a; }
Disclaimer: Just junk off the top of my head, untested, use at your own risk, if it breaks you get to keep the bits, etc.
...roboticus
|
|---|