Very stupid question but.....

B

Bill H

After using perl on webservers for cgi and processing data files for
past 8 years I have never had to do this tilll today and just can't
seem to figure out how.

"Basic"lly, how do I do input a line from the keyboard in perl? I want
to do something as simple as (shown in Basic):

print "What is the filename?";
input filename$



Bill H
 
L

Lambik

Bill H said:
After using perl on webservers for cgi and processing data files for
past 8 years I have never had to do this tilll today and just can't
seem to figure out how.

"Basic"lly, how do I do input a line from the keyboard in perl? I want
to do something as simple as (shown in Basic):

print "What is the filename?";
input filename$

print What is the filename ";
my $filename = <STDIN>;
 
M

Mirco Wahab

Bill said:
"Basic"lly, how do I do input a line from the keyboard in perl? I want
to do something as simple as (shown in Basic):

print "What is the filename?";
input filename$


...
sub Input { syswrite STDOUT, $_[0], length $_[0]; $_[1] = <> }

Input "What is the filename?", $filename;

print "\noh, its ", $filename;
...

Regards

M.
 
M

Mirco Wahab

Lambik said:
print What is the filename ";
my $filename = <STDIN>;

Aside from the typo, this wouln't
(imho) work as expected on some
systems, but you could "unbuffer" by hand:

{
local $| = 1;
print "What is the filename ";
$filename = <STDIN>;
}



Regards

M.
 
M

Mirco Wahab

Peter said:
http://perl.plover.com/FAQs/Buffering.html:

STDOUT is flushed automatically when we read from STDIN.

Yea, right. "Suffering from buffering" is a good source.

But the above would (afaik) work "automagically"
*only* if perl determines to read/write directly
to an interactive terminal.

If not (as in IDEs or development environments or files),
it won't work.

Please correct me if I'm wrong here.

Regards

Mirco
 
J

Joe Smith

Mirco said:
But the above would (afaik) work "automagically"
*only* if perl determines to read/write directly
to an interactive terminal.

If not (as in IDEs or development environments or files),
it won't work.

Please correct me if I'm wrong here.

Files are not interactive, so it does not matter.
For an IDE that uses a pty, -t(STDIN) returns true, so that is taken care of.
 
T

Ted Zlatanov

BH> After using perl on webservers for cgi and processing data files for
BH> past 8 years I have never had to do this tilll today and just can't
BH> seem to figure out how.

BH> "Basic"lly, how do I do input a line from the keyboard in perl? I want
BH> to do something as simple as (shown in Basic):

BH> print "What is the filename?";
BH> input filename$

Unless you are doing *very* simply input, you probably will find
Term::ReadLine more useful than <> for reading input.

Ted
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top