Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Anonymous subroutines (why and what for)

by jdporter (Paladin)
on Dec 11, 2023 at 20:25 UTC ( [id://11156261]=note: print w/replies, xml ) Need Help??


in reply to Re: Anonymous subroutines (why and what for)
in thread Anonymous subroutines

I believe this is an excellent summary. Thanks, LanX!

One context in which I've seen anonymous subs used a lot is where you have code chunks being defined within, and called by, a framework. Execution of the code takes the form of eval'ing the code, so it has lexical context just like a sub. If, in such a code chunk, you want to define a sub so you can call it multiple times (or any other reason), you have to do it as an anonymous sub, since you can't do it any other way (at least not without getting a "won't stay shared" warning). (But your other comment is important too.)

  • Comment on Re^2: Anonymous subroutines (why and what for)

Replies are listed 'Best First'.
Re^3: Anonymous subroutines (why and what for)
by LanX (Saint) on Dec 12, 2023 at 00:29 UTC
    Thanks!

    I'm not sure I've ever worked with such kind of a "code template system" ° but I wanted to add metaprogramming anyway. (Done)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

    °) maybe apart the monastery's codebase ;)

      ;-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-09-12 03:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (15 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.