Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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 musing on the Monastery: (8)
As of 2015-11-30 22:41 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (788 votes), past polls