Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Sorting by numbers

by kidd (Curate)
on Aug 14, 2002 at 18:45 UTC ( #190188=perlquestion: print w/ replies, xml ) Need Help??
kidd has asked for the wisdom of the Perl Monks concerning the following question:

I have a bunch of data which I display sorting it out by numbers:

9 8 7 ... 3 2 1

I thought it worked fine...until I got to number 10...which displays just before 1....

I thought of adding 0 before the one digit numbers...but maybe there is a better way to achieve this...

10 9 8 ... 3 2 1

Thanks

Comment on Sorting by numbers
Select or Download Code
Replies are listed 'Best First'.
Re: Sorting by numbers
by the_slycer (Chaplain) on Aug 14, 2002 at 18:52 UTC
    Sounds like you are doing just a sort list
    What you need is sort { $a <=> $b } list See the perlfunc manpage for sort
Re: Sorting by numbers
by mp (Deacon) on Aug 14, 2002 at 18:52 UTC
    From: perldoc -f sort

    # sort numerically ascending @articles = sort {$a <=> $b} @files;
      or to get them in the order he posted in: @a = sort { $b <=> $a } @list; =)

      -Waswas

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2015-07-07 23:04 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 (93 votes), past polls