Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: for loop syntax difference

by Sue D. Nymme (Monk)
on Aug 28, 2009 at 14:26 UTC ( [id://791924]=note: print w/replies, xml ) Need Help??


in reply to for loop syntax difference

The documentation you're reading is out of date.

Once upon a time, when you looped for (1..1000), perl would create a list of one thousand elements in memory, and then loop over that list. Looping C-style (for ($x=1; $x<=1000; $x++)) would not have the initial overhead of creating the list, nor the overhead of holding that list in memory. For short loops, like your 1-10 example, this was a trivial difference.

In any case, this is no longer an issue. Perl no longer creates the throwaway list in memory; the two are basically equivalent now.

Log In?
Username:
Password:

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

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

    No recent polls found