We don't bite newbies here... much | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
It's not only a matter of merely simulating the behavior of shift and unshift, it may have a lot to do with execution efficiency since a reverse is an expensive operation. It involves creating a new list and populating it with the elements of the original in O(n) time (n = length of the list). A shift is typically O(1) time since it involves just taking out the first element of which you have the address anyway -- it's the start of the list -- and making the second element the first. The same holds for unshift which is a simple insertion at the beginning of the list. So for reasons of efficiency, you really want shift and unshift, not only to make code look more elegant. Hope this helps, -gjb- In reply to Re: Re: Dealing with Lists and Arrays
by gjb
|
|