Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > <STDIN> blues

Reply
Thread Tools

<STDIN> blues

 
 
Tan Rezaei
Guest
Posts: n/a
 
      06-28-2003
I have this bit of code on a win2k Server:

-----------------------------------------
#!E:\Perl\bin\perl.exe
print "\n\n Productline (QA, PROD, ...)?\n ";
chop($opt_p=<STDIN>);

print "\n\n Company (0001, 1000, 1001, \.\.\.) ? \n";
chop($opt_c=<STDIN>);

if ($opt_c =~ /\D/) { warn "Company number contains non digits"}

print "\n\n Ready to Process Company $opt_c in Productline $opt_p
(Y/N)? \n";
chop($run=<STDIN>);
-----------------------------------------

Now when I run this, it does not prompt me for the variables but if I
enter all three of them then I will get the questions.

If I comment out all the lines with <STDIN> then I get all the promts
immediately.

Now this actually works fine on one machine and I only get this
problem when I put the file on the server.

Is there something about terminal settigs or clearing the buffer that
might be the issue. If so, how do I clear the screen buffer? This is
one of those things that you just don't want to waste your time on.
And it is really killing me.

Any help at all would be greatly appreciated.

thanks in advance

T
 
Reply With Quote
 
 
 
 
Kent Paul Dolan
Guest
Posts: n/a
 
      06-29-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (Tan Rezaei) wrote:

> I have this bit of code on a win2k Server:


Ah, someone wise enough to post the source code in a nicely trimmed
down example without being asked!

> -----------------------------------------
> #!E:\Perl\bin\perl.exe
> print "\n\n Productline (QA, PROD, ...)?\n ";
> chop($opt_p=<STDIN>);
>
> print "\n\n Company (0001, 1000, 1001, \.\.\.) ? \n";
> chop($opt_c=<STDIN>);
>
> if ($opt_c =~ /\D/) { warn "Company number contains non digits"}
>
> print "\n\n Ready to Process Company $opt_c in Productline $opt_p
> (Y/N)? \n";
> chop($run=<STDIN>);
> -----------------------------------------
>
> Now when I run this, it does not prompt me for the variables but if I
> enter all three of them then I will get the questions.
>
> If I comment out all the lines with <STDIN> then I get all the promts
> immediately.
>
> Now this actually works fine on one machine and I only get this
> problem when I put the file on the server.
>
> Is there something about terminal settigs or clearing the buffer that
> might be the issue. If so, how do I clear the screen buffer? This is
> one of those things that you just don't want to waste your time on.
> And it is really killing me.
>
> Any help at all would be greatly appreciated.
>
> thanks in advance
>
> T


It's been too long since I committed Perl with malice aforethought to
give you a detailed fix, but indeed your problem is buffering; when
you write from (any Unix program at all, and probably elsewhere),
unless you force matters to occur otherwise, written output is
buffered in memory until a standard bufferful (probably 512 bytes, but
can vary with OS) is ready to be written to "disk" (which in this case
is your screen) in a nice tidy efficient single write.

Sadly, that isn't at all what you want to have happen here.

The name of the magic you need is a forced "flush" of the STDOUT
stream, but I don't remember how to spell that in Perl, and the triage
of living homeless has left all my computer language manuals sold at
auction years ago. Still, perhaps that will be clue enough to help
you find the answer yourself.

[It's also possible that some variant of writing in "raw" mode will
work, but that is really inefficient, and all you need in this
instance is to get the characters out one whole line at a time, not
each single character separately pushed with an immediate I/O action.]

And by the way, in general, "chomp" is friendlier than "chop", you
really don't want to use "chop" where you are trying explicitly to
trim a newline, but only where you _really, really_ want to trim the
last byte of a string, no matter _what_ value that byte contains.
Usually that is only true when you are treating string contents as
strings of binary octets rather than as strings of characters. To
make a bad pun reversed, the habitual use of "chop" can bite you,
while "chomp", strangely, will not.

xanthian.
 
Reply With Quote
 
 
 
 
ThePotPlants
Guest
Posts: n/a
 
      06-29-2003

"Tan Rezaei" <(E-Mail Removed)> wrote:
> I have this bit of code on a win2k Server:
>
> -----------------------------------------
> #!E:\Perl\bin\perl.exe
> print "\n\n Productline (QA, PROD, ...)?\n ";
> chop($opt_p=<STDIN>);
>
> print "\n\n Company (0001, 1000, 1001, \.\.\.) ? \n";
> chop($opt_c=<STDIN>);
>
> if ($opt_c =~ /\D/) { warn "Company number contains non digits"}
>
> print "\n\n Ready to Process Company $opt_c in Productline $opt_p
> (Y/N)? \n";
> chop($run=<STDIN>);
> -----------------------------------------
>
> Now when I run this, it does not prompt me for the variables but if I
> enter all three of them then I will get the questions.
>
> If I comment out all the lines with <STDIN> then I get all the promts
> immediately.
>
> Now this actually works fine on one machine and I only get this
> problem when I put the file on the server.
>
> Is there something about terminal settigs or clearing the buffer that
> might be the issue. If so, how do I clear the screen buffer? This is
> one of those things that you just don't want to waste your time on.
> And it is really killing me.
>
> Any help at all would be greatly appreciated.
>
> thanks in advance
>
> T


Looking at it a little differently...

It looks to me like you are mixing the use of @ARGV and GETOPT::STD (given
away by your variables $opt_c & $opt_p)
I posted a question related to getopt, have a look at it, you may want to
consider using that instead.
Ask yourself if you want to execute the programme and pass it variables, or
if you want to prompt the user for input.

P






 
Reply With Quote
 
Tan Rezaei
Guest
Posts: n/a
 
      06-29-2003
"ThePotPlants" <(E-Mail Removed)> wrote in message news:<m3tLa.57155$(E-Mail Removed)>...
> "Tan Rezaei" <(E-Mail Removed)> wrote:
> > I have this bit of code on a win2k Server:
> >
> > -----------------------------------------
> > #!E:\Perl\bin\perl.exe
> > print "\n\n Productline (QA, PROD, ...)?\n ";
> > chop($opt_p=<STDIN>);
> >
> > print "\n\n Company (0001, 1000, 1001, \.\.\.) ? \n";
> > chop($opt_c=<STDIN>);
> >
> > if ($opt_c =~ /\D/) { warn "Company number contains non digits"}
> >
> > print "\n\n Ready to Process Company $opt_c in Productline $opt_p
> > (Y/N)? \n";
> > chop($run=<STDIN>);
> > -----------------------------------------
> >
> > Now when I run this, it does not prompt me for the variables but if I
> > enter all three of them then I will get the questions.
> >
> > If I comment out all the lines with <STDIN> then I get all the promts
> > immediately.
> >
> > Now this actually works fine on one machine and I only get this
> > problem when I put the file on the server.
> >
> > Is there something about terminal settigs or clearing the buffer that
> > might be the issue. If so, how do I clear the screen buffer? This is
> > one of those things that you just don't want to waste your time on.
> > And it is really killing me.
> >
> > Any help at all would be greatly appreciated.
> >
> > thanks in advance
> >
> > T

>
> Looking at it a little differently...
>
> It looks to me like you are mixing the use of @ARGV and GETOPT::STD (given
> away by your variables $opt_c & $opt_p)
> I posted a question related to getopt, have a look at it, you may want to
> consider using that instead.
> Ask yourself if you want to execute the programme and pass it variables, or
> if you want to prompt the user for input.
>
> P


Yes, I was using the GETOPT::STD before until I found out who the
users are. They are asking to get prompted for every question as
opposed to run time parameters.

I had to fix this yesterday, so I ended up using warn statements
instead of print and those had no trouble showing up. I know its a
cheap way out but it worked for yesterday. I am going to try some of
people's suggestions today. Thank you all, those are all some great
suggestions. I've been using Perl for a couple of years but have never
really needed to do anything advanced so I am stuck using the most
elementary functions.

P.S. Where is a good place to get some good example code?

Thanks
 
Reply With Quote
 
Tan Rezaei
Guest
Posts: n/a
 
      07-08-2003
(E-Mail Removed) (Tan Rezaei) wrote in message news:<(E-Mail Removed). com>...
> I have this bit of code on a win2k Server:
>
> -----------------------------------------
> #!E:\Perl\bin\perl.exe
> print "\n\n Productline (QA, PROD, ...)?\n ";
> chop($opt_p=<STDIN>);
>
> print "\n\n Company (0001, 1000, 1001, \.\.\.) ? \n";
> chop($opt_c=<STDIN>);
>
> if ($opt_c =~ /\D/) { warn "Company number contains non digits"}
>
> print "\n\n Ready to Process Company $opt_c in Productline $opt_p
> (Y/N)? \n";
> chop($run=<STDIN>);
> -----------------------------------------
>
> Now when I run this, it does not prompt me for the variables but if I
> enter all three of them then I will get the questions.
>
> If I comment out all the lines with <STDIN> then I get all the promts
> immediately.
>
> Now this actually works fine on one machine and I only get this
> problem when I put the file on the server.
>
> Is there something about terminal settigs or clearing the buffer that
> might be the issue. If so, how do I clear the screen buffer? This is
> one of those things that you just don't want to waste your time on.
> And it is really killing me.
>
> Any help at all would be greatly appreciated.
>
> thanks in advance
>
> T



Well I tried

$| = 1;
at the begining of the script and everything worked.
I thought I should post it in case someone else runs into this issue.

Thank you
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
292 Blues... RL \(Bob\) Coppedge, MCSE/MCDBA/MCT MCSE 6 12-29-2007 12:00 AM
Wireless Configuration Blues 1131AP notkailen Cisco 1 03-15-2006 09:02 PM
Network blues =?Utf-8?B?VGltc2FsaXZl?= Wireless Networking 9 12-23-2004 07:22 AM
File Handle Reading Blues: Rereading a File Handle for Input Dietrich Perl 1 07-22-2004 10:02 AM
reformat blues with user controls Max ASP .Net 0 10-16-2003 04:52 PM



Advertisments