in reply to (lestrrat) Re: Trying to simulate a CLI using hashes...
in thread Trying to simulate a CLI using hashes...
use strict; my $input; my %commands; my $cmd; my %commands = ( greeting => \&greeting(), quit => \&end_program(), ); chomp( $input = <STDIN> ); my( $cmd, @args ) = split( /\s+/, $input ); if( defined( $commands{ $cmd } ) ) { $commands{ $cmd }->( @args ); } sub greeting { print "Weclome\n"; } sub end_program { print("Ending Program\n"); die; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: (lestrrat) Re: Trying to simulate a CLI using hashes...
by lestrrat (Deacon) on Jan 22, 2002 at 07:36 UTC |