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

You're surely doing something wrong if you have many variables whose names end with a number.
my @n; while (@n < 5) { if (@n) { print "Type in another number: "; } else { print "Type in a number: "; } chomp( my $n = <STDIN> ); push @n, $n; } print "$_\n" for sort { $a <=> $b } @n;

Update: Added compare function as per reply.

Replies are listed 'Best First'.
Re^2: How to make perl sort these values in order?
by CountZero (Bishop) on Aug 07, 2011 at 06:58 UTC
    Or
    print "$_\n" for sort { $a <=> $b } @n;
    if you want the results sorted numerically rather than ASCIIbetically.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James