Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: variable subroutine call

by pfaut (Priest)
on Dec 12, 2007 at 01:24 UTC ( #656530=note: print w/replies, xml ) Need Help??


in reply to variable subroutine call

You can use a variable containing the name of a function as a reference to call the function.

sub say { print $_[0],$/ }; $x = 'say'; $x->('hello');

Although Perl supports this, you shouldn't use it because it can be very dangerous. This is disallowed when 'use strict refs' is in effect. meraxes solution is better. Store references to allowed functions in a hash and allow the user to choose a function by entering its key value.

90% of every Perl application is already written.
dragonchild

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://656530]
help
Chatterbox?
[chacham]: android studio is such a pain
[Corion]: I found Android Studio quite nice as a Java IDE, but then, I didn't try anything serious with it

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2017-03-29 07:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (344 votes). Check out past polls.