http://qs321.pair.com?node_id=11114511


in reply to pop and shift not reversible

You are checking the truth of $next = pop @x rather than the definedness. 0 is false.

use strict; use warnings; my @x = (0, 1, 2, 3); my $next; my $first = pop @x ; print "x $#x pop ",$first,"->"; while ( $next = pop @x ) { print ",",$next } print "\n"; @x = (0, 1, 2, 3); $first = pop @x ; print "x $#x pop ",$first,"->"; while ( defined ($next = pop @x) ) { print ",",$next } print "\n";