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


In reply to Re: Re: Can you determine the number of References to a value? by shotgunefx
in thread Can you determine the number of References to a value? by shotgunefx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.