Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: $#array issue

by QM (Vicar)
on Jun 15, 2009 at 18:44 UTC ( #771753=note: print w/ replies, xml ) Need Help??


in reply to $#array issue

Lot's of good answers. Maybe this is short and sweet?

@array = (1..9); while (@array){ print +(pop @array), "\n"; }

If you really need that element for something along with the print, you can do this:

@array = (1..9); while (@array){ my $last = pop @array; do_something($last); print "$last\n"; }

-QM
--
Quantum Mechanics: The dreams stuff is made of


Comment on Re: $#array issue
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (17)
As of 2014-10-21 09:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (99 votes), past polls