Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Sort a long list of hosts by domain

by Brovnik (Hermit)
on Jun 24, 2001 at 00:18 UTC ( [id://91002]=note: print w/replies, xml ) Need Help??


in reply to Sort a long list of hosts by domain (code)

This is perfect for the Schwartzian Transform.
my @sorted = map { $_->[1] } sort { $a->[0] cmp $b->[0] } map { [join('.',reverse split(/\./)),$_] } @unsorted;
or, to put it into the form you provided,
my $noodle = join($/, map { sprintf("%64s",$_->[1]) } sort { $a->[0] cmp $b->[0] } map { [join('.',reverse split(/\./)),$_] } keys %hash );
Update: to point to merlyn's original post.
--
Brovnik

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-03-29 07:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found