Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Fun with Closures

by Schemer (Scribe)
on Mar 25, 2003 at 02:13 UTC ( #245595=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    # an object is simply a closure with a hash of closures
    sub make_object {
    ...
                $msg{$m}->(@_) : print "unknown message\n";
        }
    }
    
  2. or download this
    # build an object
    my $object = make_object();
    ...
    &$object("get-self")->("add-msg", "test", sub {print "test ok!\n"});
    &$object("test"); # ==> display "test ok!"
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://245595]
Front-paged by diotalevi
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2022-08-15 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?