Just a thought, but closure sort of has a special meaning in perl5. While in most cases a closure has the convential "subroutine which runs in the context it was declared" meaning, ive found perlers often use it also in the sense of "Coderef to an anonymous subroutine". This probably comes from the fact that the closure mechanism in perl is partially broken, in that the common meaning can only apply to an anonymous subroutine, not an explicitly named subroutine, attempting to do so will result in "not shared" warnings. Also note that there are subtle bugs (thankfully rarely encountered) even when anonymous subs are used. (See Funkyness with closures... for an example)

There are already good examples of what you can do with closures posted so I wont give an example (aside from the others check out perltoot,perltootc for some ideas), but if you arent already familiar with the idea of anonymous subroutines/function pointers/coderefs then they are also well worth becoming aquainted with (think dispatch mechanisms and dynamic iterators).

BTW, id say a lot of perlers would include closures on their "funky things I like perl because of" list, right alongside regexes,map and grep. Have fun.

Yves / DeMerphq
--
When to use Prototypes?


In reply to Re: Why are closures cool? by demerphq
in thread Why are closures cool? by mr.dunstan

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.