http://www.perlmonks.org?node_id=305801

dvergin has asked for the wisdom of the Perl Monks concerning the following question:

Given some program that produces output over time, let's call it "blackbox.pl":
#!/usr/bin/perl use warnings; use strict; for my $step (1..4) { sleep 3; print "Step $step\n"; }
I had expected (and wanted) the following code to capture and print out that output as it occurred:
#!/usr/bin/perl use warnings; use strict; $|++; open PIPE1, "./blackbox.pl |"; while ( <PIPE1> ) { # ...Filter and munge $_ print $_; } close PIPE1;
But what it does (with or without the $|++) is wait until blackbox.pl finishes and then it prints out all the output at once.

What am I doing wrong? How can I capture and print the output of blackbox.pl as it occurs? (Needless to say, the real program will be doing some filtering and munging along the way.)

TIA, David

------------------------------------------------------------
"Perl is a mess and that's good because the
problem space is also a mess.
" - Larry Wall