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

Re: "Dynamic" dispatch tables

by roboticus (Chancellor)
on Apr 29, 2011 at 18:12 UTC ( [id://902051]=note: print w/replies, xml ) Need Help??


in reply to "Dynamic" dispatch tables

elTriberium:

It's really pretty simple to use a dispatch table, so no module is really required. For example:

$ cat disp_tbl.pl #!/usr/bin/perl use strict; use warnings; use feature ':5.10'; sub foo { say "foobar" } sub bar { say "barbaz" } my %DT = ( foo=>\&foo, bar=>\&bar, quit=>sub { die "END!"; } ); say "Commands are foo, bar and quit\n"; while (<>) { chomp; if (exists $DT{$_}) { $DT{$_}(); } } $ perl disp_tbl.pl Commands are foo, bar and quit foo foobar bar barbaz quit END! at disp_tbl.pl line 9, <> line 3.

Update: By themselves, dispatch tables aren't a security concern. As long as the user isn't able to have perl (or the shell, database...) execute a string that the user enters, then everything is under the programs control.

Update: Ooops! mr_mischief mentioned that very thing as I was editing my node.

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-20 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found