Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Strict, strings and subroutines

by gbarr (Monk)
on Oct 10, 2001 at 16:49 UTC ( [id://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);

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-26 03:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found