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

Re: cull

by hossman (Prior)
on Mar 31, 2007 at 23:35 UTC ( [id://607655]=note: print w/replies, xml ) Need Help??


in reply to cull

I haven't seen any other implementations of a function like this before -- but i haven't exactly been looking for one either.

My only suggestion would be using wantarray to check your calling context -- if it's void or scalar don't bother maintaining @culled, just record the count and save yourself some memory.

Update: One other thing I just noticed; I'm no expert on the internal optimizations of the perl compiler, but would a C style for loop be a little better in this case? I seem to recall hearing that for (1..$big_num) had been optimized to not create a big ass list of sequential integers, but I'd be surprised if it's smart enough to make the same optimization in your reverse case.

Replies are listed 'Best First'.
Re^2: cull
by betterworld (Curate) on Apr 01, 2007 at 03:23 UTC
    but I'd be surprised if it's smart enough to make the same optimization in your reverse case
    Unfortunately there's no surprise for you:
    $ perl -we 'for(0..999999999){last}' $ perl -we 'for(reverse 0..999999999){last}' Out of memory! $
    (That's perl 5.8.8.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 20:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found