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.)