Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: pop and shift not reversible

by talexb (Canon)
on Mar 20, 2020 at 13:39 UTC ( #11114518=note: print w/replies, xml ) Need Help??


in reply to pop and shift not reversible

You may have got this already, but I'm going to explain without code fragments. pop takes an element off the end of an array; it matches up with push, which adds an element to the end of an array. shift takes an element off the beginning of an array; it matches up with unshift (OK that one is maybe a little clumsily named), which adds an element to the beginning of an array.

So, to answer the premise your title proposes, Nope -- reverse pop with push, and reverse shift with unshift. Still not convinced? Hop into the debugger and try a few examples, live, and see how Perl works. :)

Alex / talexb / Toronto

Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2021-09-18 18:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?