Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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?
shmem doesn't have mp3info, but mp3info2 - which is a perl script ;-)
[marioroy]: my @music_times = qx(find \$HOME/Music/ Albums/ -type f -iname '*.mp3' -exec mp3info -p "%S\\\n" {} \\;);
[marioroy]: might need 2 or 3 backslash for \n. Also \\;
[Lady_Aleena]: shmem, there is MP3::Info/
[Discipulus]: too much complex qx when you know perl are better to avoid
[marioroy]: might need to backslash \'*.mp3\'
[marioroy]: It's a quoting issue inside qx. It's File::Find or qx. LA chooses qx. Almost there.
[marioroy]: Also \"%S\\\n\" oh my, not fun.
[Discipulus]: good night folks

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2017-04-23 21:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (432 votes). Check out past polls.