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

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.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2021-10-28 12:31 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (96 votes). Check out past polls.