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

Re: sorting/output

by dpuu (Chaplain)
on Dec 09, 2004 at 21:25 UTC ( #413690=note: print w/ replies, xml ) Need Help??


in reply to sorting/output

I found the code a bit confusing, but I think what is happenning is that you are creating an array that maps a distance from the centre to a record -- but you don't account for the possibility of two records with the same distance.

The approach you probably want to use is to create a reshref for each record, and then sort those by distance. i.e.

while (<LINE>) { @fields = split; my $record = { ra => ..., prob => ..., dist => ..., }; push @records, $record; } sub by_distance { $a->{dist} <=> $b->{dist} } @records = sort by_distance @records;

You can then iterate ocver the records, and print them.

--Dave
Opinions my own; statements of fact may be in error.


Comment on Re: sorting/output
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (12)
As of 2015-07-31 10:00 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 (276 votes), past polls