Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Naming Subs

by Zaxo (Archbishop)
on Jan 12, 2003 at 00:21 UTC ( [id://226168]=note: print w/replies, xml ) Need Help??


in reply to Naming Subs

A dispatch table is a neat way to do that. It is a hash, keyed by your input string, with code references as values.

my %action = ( go => sub { # some code }, turn => \&turn_sub, #... } while (1) { my $act = <>; chomp $act; # parsing can get fancier here exists $action{$act} and $action{$act}->(); }

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Naming Subs
by eoin (Monk) on Jan 12, 2003 at 00:27 UTC
    Thanks I'll give it a try and let you know the results.


    All the Best, Eoin...

    If everything seems to be going well, you obviously don't know what the hell is going on.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2024-04-25 01:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found