Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Strict, strings and subroutines

by gbarr (Monk)
on Oct 10, 2001 at 16:49 UTC ( #117982=note: print w/ replies, xml ) Need Help??


in reply to Strict, strings and subroutines

Others have given you several solutions, but there is one more. strict will only cause an error if you try to call the sub by using a string. It does not stop you taking a reference. So

my $sub = \&{'do_'.$type}; $sub->();

Is perfectly legal. But if you don't want the extra variable

(\&{'do_'.$type})->();

will work too. But the benefit of using the variable is that you can check that the sub actually exists with

my $sub = \&{'do_'.$type}; die "Unknown sub 'do_$type'" unless defined(&$sub);


Comment on Re: Strict, strings and subroutines
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2014-10-26 05:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (151 votes), past polls