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
In Section
Seekers of Perl Wisdom