Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How to make perl sort these values in order?

by james2vegas (Chaplain)
on Aug 07, 2011 at 00:41 UTC ( #919009=note: print w/replies, xml ) Need Help??


in reply to How to make perl sort these values in order?

First off you should chomp the values you get from readline (<>), then sort them, the default sort is not numeric so something like:

#!/usr/bin/perl use strict; use warnings; print "Type in a number."; chomp(my $n1 = <>); print "Type in another number."; chomp(my $n2 = <>); print "Type in another number."; chomp(my $n3 = <>); print "Type in another number."; chomp(my $n4 = <>); print "Type in another number."; chomp(my $n5 = <>); print "$_\n" for sort { $a <=> $b } ($n1,$n2,$n3,$n4,$n5);
I also added the use strict; use warnings;

You should consider chomping in a loop into an array.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://919009]
help
Chatterbox?
[erix]: hm zipfile-SQLite sounds useful, have you tried it already, Corion?
[erix]: and good morning (sorry :))
[Corion]: erix: Naah, I just saw the announcement and remembered that discussion. Maybe I'll try building a DBD::SQLite with the zip stuff built-in, just for fun
[Corion]: Oh - and a good morning to you too :)

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2018-01-24 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (256 votes). Check out past polls.

    Notices?