in reply to Trying to simulate a CLI using hashes...
Well, first off, why don't you just make you orignal hash something like this:
my %commands = ( cmd1 => \&do_cmd1, cmd2 => \&do_cmd2, .... );
This buys you the flexibility of passing arguments to the subs, if you so wish to
## untested, just something I thought up right now chomp( $input = <STDIN> ); my( $cmd, @args ) = split( /\s+/, $input ); if( defined( $commands{ $cmd } ) ) { $command{ $cmd }->( @args ); }
Obviously you would need to do more error checking and what not, but you get the idea. Also, if you might want to try useing Term::ReadLine and its related modules for soemthing like this. It's quite handy
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (lestrrat) Re: Trying to simulate a CLI using hashes...
by thoth (Novice) on Jan 22, 2002 at 07:08 UTC | |
by lestrrat (Deacon) on Jan 22, 2002 at 07:36 UTC |