A couple of comments on style:
- You didn't use warnings or strict, even though your code seems to run fine with warnings turned on. The only difference for turning on strict is localizing %find_cache with my. My testing wasn't that extensive, just a little playing around, so there may be some deeper issues that i completely missed.
- On the wantarray inside the if (&$coderef) block, it seems to read better if you put the return outside the ?: operator. This isn't necessarily like (ab)using map in a void context, but i consider it to be roughly similar (map has the for loop, ?: has the if/else block)
- Since you don't sprinkle $_ anywhere but inside the for loop, the local $_; call can probably be moved to just inside the for loop. Whenever i see that at the top of a block i start expecting heavy usage of $_ to go on, but in this case i was reading carefully for no reason. Putting localization code in the smallest possible block is also generally a good thing (imho).
- You include a hook for giving a starting point, but nothing for the ending point. It would be a simple change and add some (admittedly only moderately useful) functionality. This seems like a natural way to extend findone further though...
- And speaking of extending code, now that you can findone you can write a wrapper to find as many as you want :-)
Unfortunately my CPAN search skills aren't very good, so i don't know if anyone else has written a lazy grep (which is what this is with some extra bells and whistles, if my understanding is correct). If no one has posted one to CPAN or if the code submitted isn't that good this seems a good candidate for packaging and sending in...
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
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:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||