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

Re: Sort hash with values

by 2teez (Vicar)
on Jun 23, 2013 at 15:59 UTC ( #1040330=note: print w/replies, xml ) Need Help??

in reply to Sort hash with values

Hi Rahul Gupta,

Really, I don't know how you wanted your hash sorted but I guess you would like to sort using "keys" since, your values from your OP are "kind" of sorted, following the numbers on the names like UEH1_system_ip, UEH11_system_ip,.. etc.
The following shows one way of doing it:

use warnings; use strict; my %ip_store = ( "" => "UEH1_system_ip", "" => "UEH11_system_ip", "" => "UEH25_system_ip", "" => "UEH111_system_ip" ); my @ip_data = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { /\.([0-9]+)$/; [ $_, $1 ] } keys %ip_store; print $ip_store{$_}, $/, $_, $/ for @ip_data;
...produces ...
UEH1_system_ip UEH25_system_ip UEH11_system_ip UEH111_system_ip

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1040330]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2018-03-19 04:04 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (232 votes). Check out past polls.