Regarding your point #3, I believe that, exactly because $a and $b are globals, closing over them doesn't make much sense. You'll have to copy the values out of the global variables (well, package lexicals), if you need to retain the values as found during the reduce call. As an aside, I've never used assignment to $a in reduce - I thought the assignment was implicit from the code return, as in:

my $sum = reduce { $a + $b } 0,1,2; # instead of my $sum = reduce { $a = $a + $b } 0,1,2;

As for you needing that second inner block, I don't know what happens there. On 5.8.5, I get a "deep recursion" in the call to $combo if I remove that second block. I guess it has something to do with pad allocation and maybe the known closure bug where you need to mention the variables to be closed over in the inner block in the intermediate block - we have a double-nesting of anonymous subs here too, the code block passed to reduce and the anonymous sub in there.


In reply to Re: Bugs? Or only in my expectations? by Corion
in thread Bugs? Or only in my expectations? by BrowserUk

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.