Howdy,
Sounds fun! This is actually one place where not using strict 'refs' may make your code more maintainable. *ducks*
This was my take:
#!/usr/bin/perl
use warnings;
use strict;
$|++;
use vars qw( $AUTOLOAD $running );
$running = 1;
while ($running) {
my $input = <>;
my ($action, @args) = split ' ', $input; # probably not robust enoug
+h
$action = lc( $action );
no strict 'refs';
&$action( @args ); # dispatch based upon action
}
sub go
{
my @args = @_;
print "You go @args\n";
}
sub quit
{
my @args = @_;
$running--;
print "Thanks for playing\n";
}
sub AUTOLOAD # catches calls to non-existent methods
{
my @args = @_;
my ($method) = $AUTOLOAD =~ m/::(:?\w+)$/;
print "I don't understand $method @args\n";
}
My session with this looked like:
Go west young man
You go west young man
Bob Ross is amazing
I don't understand bob Ross is amazing
quit
Thanks for playing
Of course, anything worth its salt would understand that Bob Ross was the man :-)
TIMTOWTDI,
-- dug
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.