Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: foreach only for a section of a list

by johngg (Abbot)
on May 05, 2012 at 12:13 UTC ( #969037=note: print w/replies, xml ) Need Help??


in reply to Re: foreach only for a section of a list
in thread foreach only for a section of a list

You could use a do block to scope the existence of $last so that it isn't left lying around.

knoppix@Microknoppix:~$ perl -Mstrict -wE ' > my @arr = qw{ one two three four }; > push @arr, do { my $last = pop @arr; say for @arr; $last }; > say qq{@arr};' one two three one two three four knoppix@Microknoppix:~$

Cheers,

JohnGG

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://969037]
help
Chatterbox?
[marto]: fun, in 2008 we (I) build a pilot system for $client, an in house youtube, they've asked me to do it again
[choroba]: again a pilot?
[marto]: yeah, the whole infrastructure has changed, and video codecs have moved on a great deal
[Corion]: marto: Redoing something on new infrastructure sounds fun. At least you can reuse your previous experience :)

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2017-07-28 09:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (425 votes). Check out past polls.