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


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.