in reply to For Loops and Reversing output
Another way to do it, without icky C-style for loops:
my $input = 'somelist'; open(my $in, "<", $input) or die "Could not open $input because $!\n"; my @sorted = sort map { chomp; "\t$_\n" } <$in>; close ($in); print @sorted; my @rocks; push @rocks, pop @sorted while @sorted; print "\n"; print "The names, backwards, are:\n", @rocks;
Or another way, that doesn't destroy @sorted in the process:
my @rocks = sort { $b cmp $a } @sorted;
|
|---|