in reply to Re^4: Sorting challenge
in thread Sorting challenge
This works, and I like that it uses as few explicit variables as I can manage while still chomping.
use v5.10; say for sort { $a <=> $b } map { chomp( my $i = <> ); $i } 1 .. <>;
Since it's just a throwaway, I suppose you could even rely on Perl's numification rules, eliminating chomp, and thus further eliminating the use of variables, making it as pure a "filter" as possible:
print for sort { $a <=> $b } map { scalar <> } 1 .. <>;
I also kind of liked this one, but it's more verbose:
my $count = <>; my @numbers; while( $count-- ) { push @numbers, scalar <>; } print for sort { $a <=> $b } @numbers;
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Sorting challenge
by hdb (Monsignor) on Jul 23, 2013 at 15:07 UTC | |
by davido (Cardinal) on Jul 23, 2013 at 15:37 UTC | |
|
Re^6: Sorting challenge
by PerlSufi (Friar) on Jul 23, 2013 at 15:24 UTC | |
by davido (Cardinal) on Jul 23, 2013 at 16:00 UTC |