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

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.


Comment on Re: For Loops and Reversing output
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://589285]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2014-08-29 04:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (275 votes), past polls