Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Re: Dealing with Lists and Arrays

by gjb (Vicar)
on Nov 11, 2002 at 15:01 UTC ( [id://211930]=note: print w/replies, xml ) Need Help??


in reply to Re: Dealing with Lists and Arrays
in thread Dealing with Lists and Arrays

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-

Replies are listed 'Best First'.
Re: Re: Re: Dealing with Lists and Arrays
by broquaint (Abbot) on Nov 11, 2002 at 15:10 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-23 11:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found