Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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


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?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (17)
As of 2015-10-06 15:11 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (152 votes), past polls