Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Naming Subs

by sauoq (Abbot)
on Jan 12, 2003 at 00:25 UTC ( [id://226169]=note: print w/replies, xml ) Need Help??


in reply to Naming Subs

Well, you could do something like that but you don't really want to anyway. You should validate the user's input.

My suggestion is to use a hash of sub references.

sub he_eats { print "You eat @_!\n"; } sub he_sleeps { print "You sleep @_!\n"; } sub he_moves { print "You move @_!\n"; } my %actions = ( eat => \&he_eats, sleep => \&he_sleeps, move => \&he_moves, ); while (<>) { chomp; my ($action, @args) = split; if (exists $actions{$action}) { $actions{$action}->(@args); } }

This is my 600th post.

-sauoq
"My two cents aren't worth a dime.";

Log In?
Username:
Password:

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

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

    No recent polls found