Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: pop and shift not reversible

by hippo (Bishop)
on Mar 20, 2020 at 10:59 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11114511]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-18 17:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found