in reply to Re: Can you determine the number of References to a value?
in thread Can you determine the number of References to a value?
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"; }
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."
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re: Can you determine the number of References to a value?
by tye (Sage) on Sep 13, 2001 at 08:25 UTC | |
by shotgunefx (Parson) on Sep 13, 2001 at 13:20 UTC |