Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Delete space at the end of a hash element

by 2teez (Priest)
on Mar 26, 2013 at 09:25 UTC ( #1025468=note: print w/ replies, xml ) Need Help??


in reply to Delete space at the end of a hash element

Or using map function, with hdb data like so:

use warnings; use strict; use Data::Dumper; my %hash = ( "apples " => 4, "oranges " => 5 ); %hash = map { my $val = $hash{$_}; s/\s+$//; $_, $val } keys %hash; print Dumper \%hash;

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me


Comment on Re: Delete space at the end of a hash element
Download Code
Re^2: Delete space at the end of a hash element
by hdb (Prior) on Mar 26, 2013 at 09:33 UTC

    So you are completely rebuilding the hash in one go, rather than adding/removing one entry at a time. That's far more elegant!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1025468]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (11)
As of 2015-07-02 21:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (45 votes), past polls