Solved

how to flush the input buffer ?

Posted on 2002-04-25
7
1,460 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
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 16

Accepted Solution

by:
maneshr earned 50 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 is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl strange behaviour 5 72
Perl, group, sort, count question 6 133
Removing file extension within a file. 4 93
Regular Expression question to filter with negation. 6 95
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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