Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Sort hash with values

by 2teez (Priest)
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]
[Discipulus]: ah! how do you say in english? .. i was sure..
[Discipulus]: ah turned
[pryrt]: I think I actually like "finished 18", because really, it's been 18years since his birth, so he's finished 18 years. :-)

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2018-01-18 20:38 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (214 votes). Check out past polls.