?
Solved

how to flush the input buffer ?

Posted on 2002-04-25
7
Medium Priority
?
1,463 Views
Last Modified: 2012-06-27
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
Comment
Question by:anil27
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 16

Accepted Solution

by:
maneshr earned 200 total points
ID: 6969078
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6970065
is this a duplicate question? Then please delete it and refund the points ;-)
0
 

Expert Comment

by:matrix187
ID: 6970075
Use [$|] :
$| = 1; enable flushing buffer
$| = 0; dissable flushing buffer
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:anil27
ID: 6970434
thanks maneshar. I was looking for output buffering parameter |++...
regards
Anil
0
 
LVL 16

Expert Comment

by:maneshr
ID: 6970471
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6970542
.. and see my (pedantic:) comment about |++
0
 

Author Comment

by:anil27
ID: 6970576
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question