Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: typeglob/symbolic reference question

by 7stud (Deacon)
on Nov 04, 2010 at 02:31 UTC ( [id://869390]=note: print w/replies, xml ) Need Help??


in reply to typeglob/symbolic reference question

Hmmm...maybe the answer to my first post is simply: you can assign to a type glob, *{"color"}, but you can't assign to a subroutine, &{"color"}.

Therefore, if you have a string and you want to dynamically define a function of the same name and then execute the function, you can:

1) Use the string to retrieve a typeglob and then assign a subroutine to the typeglob, which serves to define the function.

*{"do_stuf"} = sub {print "hello"};

2) Subsequently, use the the string as a symbolic reference to retrieve the function and execute it.

&{"do_stuff"}();

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (10)
As of 2024-04-18 14:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found