Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: pop and shift not reversible

by hippo (Chancellor)
on Mar 20, 2020 at 10:59 UTC ( #11114511=note: print w/replies, xml ) Need Help??


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";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11114511]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2020-06-01 17:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (5 votes). Check out past polls.

    Notices?