reading from stdin via pipe, buffering?

R

Rudy Gevaert

Hi,

I have written an perl program that read from stdin:
while(<STDIN>)
{
chomp
do_it($_);
}
Data is fed to it via a pipe:

cat myfile | ./myprogram

When running the program, the program doesn't always read the whole
line. I'm guessing this has something to do with the stdin buffer.

I would like to know how I can make that perl gets the whole line. As
it is clearly failing from time to time.

Thanks in advance,

Rudy
 
R

Rodrick Brown

Rudy Gevaert said:
Hi,

I have written an perl program that read from stdin:
while(<STDIN>)
{
chomp
do_it($_);
}
Data is fed to it via a pipe:

cat myfile | ./myprogram

When running the program, the program doesn't always read the whole line.
I'm guessing this has something to do with the stdin buffer.

I would like to know how I can make that perl gets the whole line. As it
is clearly failing from time to time.

Thanks in advance,

Rudy

Try disabling buffering $|++;
 

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

No members online now.

Forum statistics

Threads
473,813
Messages
2,569,696
Members
45,483
Latest member
TedDvb6626

Latest Threads

Top