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

Re: Access functions by name

by Arunbear (Prior)
on Jun 16, 2009 at 11:10 UTC ( #771983=note: print w/replies, xml ) Need Help??


in reply to Access functions by name

Either use UNIVERSAL's "can" method, or look up the name in the symbol table hash %FunctionsSet:: (see perlmod) e.g.
use strict; use warnings; package FunctionsSet; sub function1 { warn "This is function1" } sub function2 { warn "This is function2" } sub function3 { warn "This is function3" } sub function4 { warn "This is function4" } package main; my @names = qw/function1 function4/; foreach my $func (@names) { FunctionsSet->can($func)->(); } my @more_names = qw/function2 function3/; foreach my $func (@more_names) { $FunctionsSet::{$func}->(); }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2021-10-22 15:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (85 votes). Check out past polls.

    Notices?