Thank you for making this wonderful tool available.
How do I use the IDE with a script that requires entering info from STDIN?
I click RUN with the following script and it just runs forever.
If I, for example, hit enter in the Console window, it prints both statements, but never allows me to enter data.
I am using the Active State 5.6.1, on Win 2000, PerlIDE release 0.9.9.
I found this in the Help. Important: If the script reads input from STDIN, the execution is stopped until the necessary data has been entered in the "Console" window. I tried using the console window, but no good.
I appreciate any suggestions. Here is the script.
$pi = 3.141592654;
print "What is the radius? I suggest 12.5 \n";
chomp ($rad = <>);
$circ = "2 * $pi * $rad";
print "The circumference of a circle $rad is $circ \n";
actually, its sitting waiting for input, if you type in, say 25, you will get a response that includes the 25. I think you need to set the $| variable to a non zero value to force autoflushing of output buffers. I just tried it and confirmed that it behaves as you would expect
OK. I am with you part way. Here is a new script.
print "Please enter a number:";
chomp ($num = <>);
print "Please enter a name:";
($nam = <>);
$res = $nam x $num;
print "The result is: \n$res ";
Here is the Console window display
fredPlease enter a number:Please enter a name:The result is:
How do I get the word "Please" in the Console window to be on a new line rather than abutting "fred"?
As to your suggestion, How do I set the $| variable and what is that variable.
Thanks very much.
You just set it:
here is an updated copy of your script:
$|=1; # force flush on each output
print "\nPlease enter a number: \n"; chomp ($num = <>);
print "\nPlease enter a name: \n"; ($nam = <>);
$res = $nam x $num;
print "\nThe result is: \n$res ";
and the new output:
Please enter a number:
Please enter a name:
The result is:
Thank you very much.
That is exactly what I am looking for.
Am I correct in thinking that the |$ is useful here in the IDE, but is not necessarily required at the beginning of all of my scripts? The script runs fine in a cygwin shell with the $| commented out.
If I remember right the $| affects the output buffering of the current selected output handle. It basically should not make much of a difference if you always use it. the
only time it might cause a problem is if your output is to a file, then you might want to
have it set to 0 so every right does not hit the disk.
For consoel I/O I would always have it on.
Thanks for posting this info guys! I was having the same problem with the ide while trying to do the same exercise from "Learning Perl"!
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.