[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] passive input request



Nicholas G. Thornton <Nicholas.G.Thornton@directory.reed.edu> wrote:

> I'm working on a program that I'd like to have command line interface. 
> Ideally it's just sit there with a prompt (ala dos...) untill you type
> something. I was wondering how I'd go about implimenting this rather than
> MacPerl::Ask() to recive input.

Important to chomp() the input first

sub usr_console {
my ($input, $done);

until (defined($done)) {

    usage();

    $input = <STDIN>;
    chomp($input);
    if ($input =~ /^some_command_here$/) {
# do command subroutine here
        }
        elsif ($input =~ /^some_other_command$/) {
# do other command subroutine here
        }
        elsif ($input =~ /^quit$/) {
            $done = "1";
        }
        else
        {
        print "$input is meaningless. Perhaps a typo?\n";
        }
    }
}

As many 'elsif' as you anticipate commands for your "shell."  These are 
very straightforward and simple to write.  You should also probably 
contemplate a simple usage() subroutine which displays a list of 
available commands.

enjoy!

--B

# Fungal Parataxonomy                   Mycology Information (Mycoinfo)
# Webmaster, Staff Writer      **The World's First Mycology E-Journal**   
# <mailto:webmaster@mycoinfo.com>            <http://www.mycoinfo.com/> 
#
# First they ignore you. Then they laugh at you. Then they fight you.
# Then you win.                                     --Mohandas Gandhi


===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org