Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: closures: anonymous subs vs function templates?

by 5haun (Scribe)
on Dec 21, 2014 at 13:02 UTC ( [id://1110952]=note: print w/replies, xml ) Need Help??


in reply to Re: closures: anonymous subs vs function templates?
in thread closures: anonymous subs vs function templates?

Thank you for that example. When edited as shown below, it clearly highlighted the differences:

use warnings; use v5.14; outer1(); exit 0; sub outer1 { my $hello = 'hello'; # local *inner = sub { my $inner = sub { say $hello; }; outer2(); } sub outer2 { # inner(); $inner->(); } __END__ Global symbol "$inner" requires explicit package name at /tmp/subtst.p +l line 20. Execution of /tmp/subtst.pl aborted due to compilation errors.

Compared with your example, we can show the more limited scope of the lexical form, as recommended by Laurent_R. Thank you both!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1110952]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-04-18 11:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found