Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: For Loops and Reversing output

by jonadab (Parson)
on Dec 12, 2006 at 14:34 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-25 07:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found