Thanks.
Basically at this point, I'm doing it just to see how. What I want to do (and have done) is create a few list operators.
elements
returns 1 or more elements. Like so
findone
Like grep only returns first matching element and index. Subsequent calls return next matching element and index or undef if array is processed.
while ( my @els = elements @array,5){
somefunc(@els).
}
while ( findone { $_ > 5 } @array }
print "Found $_\n";
}
# or
while (my ($val,$index) = findone { $_ > 5 } @array }
print "Found $val in position $index\n";
}
The problem is that I want to be able to nest calls to it which means I have to keep track of the current list. By taking a reference to them, I am stopping it from getting garbaged collected. The references are stored in a hash. What I'd like to do is loop through each and see if the ref count is 1. If it is, then it has to be me and I can "I think" safely delete my reference to it.
UPDATE
Does anyone else see value in these constructs? I think there handy. One of the things that I love about Perl is how much you can say in so few words. I was thinking of making the eleements operator possibly take a CODEREF so thay you could grab all the elements up to and including the element that returns true.
-Lee
"To be civilized is to deny one's nature." |