simonz has asked for the wisdom of the Perl Monks concerning the following question:
Hi
I am trying to write an interactive perl script which will check the commandl line for a message and if the check is successful it will assign 'yes' otherwise will take it from the <STDIN>. Based on the answer, if it is 'yes' the script should continue else it would take the necessary action.
Please refer to the code below which I am trying
use Term::ReadLine; # Initialize the term variable for the keyborad input my $TERM = new Term::ReadLine 'Installer'; my $OUT = $TERM->OUT || \*STDOUT; my $prompt = "Would you like to continue\n"; my $ans; $ans = ($TERM->readline($prompt)) ? : 'yes' :<STDIN> ; chomp($ans); print "ans is $ans \n"; if($ans =~ /yes/) { print "yes and continue\n"; } else { print "no and take action\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to take user input from command line and continue
by mtmcc (Hermit) on Apr 10, 2014 at 10:42 UTC | |
|
Re: how to take user input from command line and continue
by Bloodnok (Vicar) on Apr 10, 2014 at 10:26 UTC |