Firstly, I wanted to say that I enjoyed your article. It's well written and very informative. :-) However, I noticed a small (debatable?) bug in your one_each() function.

The problem is that you don't check to make sure that the function is being called on the same two arrays each time. Consider:

my @a = qw(a0 a1 a2); my @b = qw(b0 b1 b2); my @c = qw(c0 c1 c2 c3 c4); my @d = qw(d0 d1 d2 d3 d4); print '(',join(',', one_each(@a, @b)),")\n"; print '(',join(',', one_each(@a, @b)),")\n"; print '(',join(',', one_each(@c, @d)),")\n"; print '(',join(',', one_each(@c, @d)),")\n";

It prints:

(a0,b0) (a1,b1) (c2,d2) ()

So, even though you're giving it two new arrays in the second two calls, it uses the position and size from the first two calls. I think an easy way to "fix" this would be to store a copy of the references to the arrays in one of your closure variables and compare it to the references passed in each time, resetting if they're different. Or, perhaps, if you didn't want the position to reset even if you use different arrays, you could just not store the sizes but, rather, check them from the arrays themselves each time. That way the sizes would be correct without resetting the position.

*shrug* Up to you, though. Just thought I'd mention it. Again, props for a well done article.

bbfu
Seasons don't fear The Reaper.
Nor do the wind, the sun, and the rain.
We can be like they are.


In reply to (bbfu) (article bug) Re (2): Taken out of Context by bbfu
in thread Taken out of Context by Petruchio

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.