Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: For Loops and Reversing output

by jonadab (Parson)
on Dec 12, 2006 at 14:34 UTC ( #589285=note: print w/replies, xml ) Need Help??

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;

Sanity? Oh, yeah, I've got all kinds of sanity. In fact, I've developed whole new kinds of sanity. You can just call me "Mister Sanity". Why, I've got so much sanity it's driving me crazy.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://589285]
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: (7)
As of 2016-10-21 12:15 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (289 votes). Check out past polls.