Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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

my $0_02,
jynx


In reply to Re: findone { coderef } @array by jynx
in thread findone { coderef } @array 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!
  • 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, 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
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (14)
    As of 2014-09-30 12:27 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (367 votes), past polls