Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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,

In reply to Re: findone { coderef } @array by jynx
in thread findone { coderef } @array by shotgunefx

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, 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
  • 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.
  • Log In?

    What's my password?
    Create A New User
    [Discipulus]: problematic? i came back after just a week of course, I forgo teverything..

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (5)
    As of 2017-12-18 11:22 GMT
    Find Nodes?
      Voting Booth?
      What programming language do you hate the most?

      Results (483 votes). Check out past polls.