Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: $#array issue

by QM (Parson)
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

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 browsing the Monastery: (7)
As of 2016-08-31 08:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The best thing I ever won in a lottery was:















    Results (427 votes). Check out past polls.