Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: sorted Hash

by Not_a_Number (Prior)
on Aug 23, 2015 at 17:03 UTC ( [id://1139588]=note: print w/replies, xml ) Need Help??


in reply to sorted Hash

I don't know how you populate your hash, but you wouldn't need to sort at all if you used an array instead:

my @SRV = ( 'zumen530n.pdg.duranto.com', 'zumen531n.pdg.duranto.com', 'zumen532n.pdg.duranto.com', # etc ); print "$_ $SRV[ $_ ]\n" for 0 .. $#SRV;

Of course, this prints 0-20 instead of 1-21, but that's easy to fix if it's important.

Update: In fact, whenever I see a hash like:

my %h = ( 1 => 'foo', 2 => 'bar', 3 => 'baz', 4 => 'quux', );

I always consider whether it wouldn't be better to use a simple array.

Replies are listed 'Best First'.
Re^2: sorted Hash
by marioroy (Prior) on Aug 24, 2015 at 06:29 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-03-28 23:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found