dragonchild,
I think the fact that the code morphed from being nothing but closures to being either/or depending on if called with an argument list made the code confusing. The commentary and the POD did explain this however. You say that none of the anonymous subs close over anything.
sub ave { my $tot; my $cnt; my $find_ave = sub { $cnt += @_; $tot += $_ for @_; return $cnt ? $tot / $cnt : undef; }; return @_ ? $find_ave->( @_ ) : $find_ave; }
This is true if ave is called like print ave(5, 10, -1, 7.3); as the anonymous sub is executed and the value 5.325 is returned - that's the way it was designed. If on the other hand, the code is called like my $ave = ave();, there most certainly is a closure returned - it closes over both $cnt and $tot. I am guessing the ternary use of @_ made you think I was trying to close over something in @_? Perhaps it would have been more clear (and better) if I had not modified the original code and re-written it as:
sub ave { my ($cnt , $tot); if ( @_ ) { $cnt += @_; $tot += $_ for @_; return $cnt ? $tot / $cnt : undef; } else { return sub { $cnt += @_; $tot += $_ for @_; return $cnt ? $tot / $cnt : undef; }; } }

Another item - you make the same mistake nearly every unique'ing function makes...
Thanks. While the POD doesn't make any promises like that, I think it would be better off that way.

Cheers - L~R

Updated: I was grumpy when I first replied as I had just woken up. Modified tone slightly to be less combative.


In reply to Re^4: RFC: Tool::Box by Limbic~Region
in thread RFC: Tool::Box by Limbic~Region

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.