Here is what I came up with..

#!/usr/bin/perl -w


use strict;

my @heir = qw/inquiry smart yes/;
my $response = "";


while ($response eq "") {
    print "Enter the hierarchical mode [$heir[0]]: ";
    chomp($response = <STDIN>);

    if(($response eq "") || ($response eq "?")) {
        print "Valid answers are:\n @heir\n";
        $response = "";
        redo;
    }

    for(my $i = 0; $i <= $#heir; $i++) {

        if(defined($heir[$i])) {
            if($response eq "$heir[$i]") {
                print "$response\n";
            }
        }
    }
}

-James


-----Original Message-----
From: Steven M. Klass [mailto:[EMAIL PROTECTED]]
Sent: Friday, February 15, 2002 1:26 PM
To: [EMAIL PROTECTED]
Subject: More help with my function


Hi all,

Here is a simple script that I am having a heck of a time with.  I think it
will become apparent what I'm trying to do.  Ask a question and validate the
answer.

&AskQuestion("Enter the hierarchical mode", my @hier = qw/inquiry smart
yes/);

sub AskQuestion {
  my $prompt = shift;
  my @answers = @_;
  my $response;
  while ( ! $response ) {
    print "$prompt [@_[0]]";
    $response = <STDIN>;
    chomp $response;
    if ( $response eq "" ) {
      $response = @answers
    }
    if ( $response eq "?") {
      $response = "";
      print "Valid answers are: \n";
      print "@answers\n";
    }
      print "\n";

    my $match;
    for ( my $i = 0; $i < @answers ; $i++ ){
      if ( $response eq $answers ){
        $match = "true";
        return $response;
      }
    }
    if ( ! $match ){ $response = "";}
  }
}

I think it must be friday or something, but could someone help me clean this
up.  I want something simple, and I think I have over-engineered this.  Any
help is appreciated!

Thanks so much.  I love this list!:)
--

 Steven M. Klass
 Physical Design Manager

 National Semiconductor Corp
 7400 W. Detroit Street
 Suite 170
 Chandler AZ 85226

 Ph:480-753-2503
 Fax:480-705-6407

 [EMAIL PROTECTED]
 http://www.nsc.com


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to