Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • I've ranted a few times on Perlmonks [] when people get "closure" and "anon sub" mixed up.

    A closure is any subroutine that needs to grab its environment because it's going out of scope, and may or may not be named.

    An anonymous subroutine is a coderef, and may or may not be a closure.

    I've got code to demonstrate all four types of subroutines (named vs anonymous, closure vs not) at Monks somewhere.

    • Randal L. Schwartz
    • Stonehenge
    • Yes, but contrary to what #london may be claiming, both of Matts samples represent closures. :) Just check against Damians definition!
      • Right. The examples at the top of this thread are named subroutines that are closures. Similar to this: BEGIN { my @DoW = qw(Sun Mon Tue Wed Thu Fri Sat); sub DoW { my $n = shift; die unless $n == int($n) and $n >= 0 and $n That's definitely a closure and yet it's a named subroutine.
        • Randal L. Schwartz
        • Stonehenge