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 reply to Re^2: foreach only for a section of a list
by johngg
in thread foreach only for a section of a list
by dizou
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |