Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: How to use require...

by fruiture (Curate)
on Jan 03, 2004 at 09:54 UTC ( #318486=note: print w/replies, xml ) Need Help??


in reply to How to use require...

Ok, autouse is of course ver elegant. I'd probably used something like the following, to save subroutne names.

my %actions = ( 'login' => sub { require Login; do_login(); }, ... );

But anyway, there's a slight problem about your code. Imagine somehow the "action" parameter is filled with nonsense, which should happen at least when you want to test your script. You'll get:

Use of uninitialized value in subroutine entry at ... Can't use string ("") as a subroutine ref while "strict refs" in use a +t .....

Simply because $query might contain "foo" (which does not exist in %actions). Just add a check to your code:

$query = 'default' unless exists $actions{ $query };

HTH.

--
http://fruiture.de

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://318486]
help
Chatterbox?
[choroba]: For my "internal" projects, I just have a thumb drive with --bare clones of the repos
[marto]: too add to my RL to do list: "This USB hard drive is damp, do you think my photos will be ok?"

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2017-01-23 10:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (192 votes). Check out past polls.