Do you know where your variables are? | |
PerlMonks |
Re: For Loops and Reversing outputby liverpole (Monsignor) |
on Dec 12, 2006 at 00:42 UTC ( [id://589201]=note: print w/replies, xml ) | Need Help?? |
Hi brusimm,
There are a lot of ways to use an array backwards. One is to simply reverse the order of the sort. For example, instead of
which is doing an implicit sort { $a cmp $b } @unsorted, you could do:
to have the order reversed at the end of the sort. Another way is to read an item one-at-a-time from the end of the list, such as in:
(Sorry, I couldn't resist using pop @rocks :-)) As a 3rd and final example, read one at a time from the end of the array using an index, using the -N notation (which reads from the -Nth value of the array each time):
s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
In Section
Seekers of Perl Wisdom
|
|