[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1466
  • Last Modified:

how to flush the input buffer ?

This is the code to get a y/n but when I make a subsequent call it does not ask for the input !

#! /in/local/bin/perl
sub demande {
my $in=0;
system("echo \"Have u modified \"");
$in = lc(getc);
$in  =~ s/ //ge;
$in  =~ s/\n//ge;
if ($in ne "y")
{
system("echo \"U are out NO BOSS .... $in\"");
exit;
}
else
{
system("echo \"U are in YES BOSS .... $in\"");
}
}
#end od demande
########MAIN#########
demande();
demande();


thanks
0
anil27
Asked:
anil27
  • 2
  • 2
  • 2
  • +1
1 Solution
 
maneshrCommented:
anil27,

".. code to get a y/n but when I make a subsequent call it does not ask for the input !..."

What exactly are you trying to do? Can you explain in plain english what you are trying to acheive?

Let me know.

This will help you get a more accurate answer, faster.

Meanwhile, here is a sample script that will be run from the command prompt.
This script will ask the user for input.

If input is Y or y, then it will print a "YES" message.
If input is N or n, then it will print a "NO" message.
if input is anything else it will print a "INVALID" message.

#!/in/local/bin/perl

$|++; ## Disable output buffering

print "Enter your reply ";
$ans=<STDIN>; ##  Read the users input

##  Remove the newline character
chomp($ans);

if ($ans=~ /^y$/i){ ##  Y or y entered!!
  print "YES\n";
}elsif ($ans=~ /^n$/i){ ##  N or n entered!!
  print "NO\n";
}else{
  print "INVALID\n";
}
0
 
ahoffmannCommented:
is this a duplicate question? Then please delete it and refund the points ;-)
0
 
matrix187Commented:
Use [$|] :
$| = 1; enable flushing buffer
$| = 0; dissable flushing buffer
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
anil27Author Commented:
thanks maneshar. I was looking for output buffering parameter |++...
regards
Anil
0
 
maneshrCommented:
anil27,

"..thanks maneshar. I was looking for output buffering parameter |++....."

You're welcome. Glad to know you got the solution you were looking for.

Meanwhile, please go ahead and delete the duplicate question that you have posted.

http://www.experts-exchange.com/perl/Q.20293458.html
0
 
ahoffmannCommented:
.. and see my (pedantic:) comment about |++
0
 
anil27Author Commented:
Yes ahoffman I agree it is better to put $|=1 than $|++ ,u never knoe :-). Moreover regarding getc I agree with you. It is not good for my requirement.
thanks
Anil
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now