bahadur has asked for the wisdom of the Perl Monks concerning the following question:
so basically i put all the commands in a hash and read from stdin and than invoke the required command.$myhash{"set time"}=\&settime; $myhash{"show time"}=\&showtime; $myhash{default}=\&error; print "Welcome to nMetrics application monitor\n"; print "Please type in a command\n"; while(<STDIN>) { chomp; $res="false"; foreach $k (keys %myhash) { if ( $k eq "$_" ) { &{$myhash{$k}}(); $res="true"; } } if ($res eq "false") { &{$myhash{default}}(); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CLI using hashes
by revdiablo (Prior) on May 30, 2005 at 01:08 UTC | |
by bahadur (Sexton) on May 30, 2005 at 01:33 UTC | |
by Anonymous Monk on May 30, 2005 at 02:45 UTC | |
by bahadur (Sexton) on May 30, 2005 at 02:54 UTC | |
by fishbot_v2 (Chaplain) on May 30, 2005 at 03:22 UTC | |
by revdiablo (Prior) on May 30, 2005 at 05:37 UTC | |
|