in reply to Naming Subs
#!/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"; }
Go west young man You go west young man Bob Ross is amazing I don't understand bob Ross is amazing quit Thanks for playingOf course, anything worth its salt would understand that Bob Ross was the man :-)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Naming Subs
by hardburn (Abbot) on Jan 13, 2003 at 16:07 UTC |