Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: typeglob/symbolic reference question

by 7stud (Deacon)
on Nov 04, 2010 at 02:31 UTC ( #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
Node Status?
node history
Node Type: note [id://869390]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2020-11-01 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (291 votes). Check out past polls.

    Notices?