in reply to Naming Subs

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

Replies are listed 'Best First'.
Re: Re: Naming Subs
by hardburn (Abbot) on Jan 13, 2003 at 16:07 UTC

    No need to shut off strict 'refs'. Take a look at the dispatch table code used in other replys.

    Remember: dispatch tables are sexy.