Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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);

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://117982]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2018-03-19 23:04 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (246 votes). Check out past polls.