zsdc wrote:
Andrew Gaffney wrote:


open MAKE, "make |";
foreach $line (<MAKE>) {
$count++;
my $percent = int(($count / $total) * 100);
print "..$percent";
}


Try changing this line:

foreach $line (<MAKE>) {

to this:

while (defined($line = <MAKE>)) {

or if you can use $_ instead of $line, then just:

while (<MAKE>) {

which is really a short way of saying:

while (defined($_ = <MAKE>)) {

What you see here has nothing to do with buffering or flushing. When you use <MAKE> in the list context provided by foreach it first reads the whole file into a temporary array and then iterates through this array. When you use <MAKE> in a scalar context, e.g. with $line=<MAKE> or implicitly in while(<MAKE>), then only one line of the input at a time is being read.

See "I/O Operators" on perldoc perlop
http://www.perldoc.com/perl5.8.0/pod/perlop.html#I-O-Operators

Is that what you were looking for?

I tried that and it still spits out all the output at the end. Here's my current code:


#!/usr/bin/perl

use strict;
use warnings;

$| = 1;
my $total = `make -n | wc -l`;
print "$total\n";
my ($count, $line);
open MAKE, "make |" or die "Can't open MAKE pipe";
foreach (<MAKE>) {
  $count++;
  my $percent = int(($count / $total) * 100);
#  print "${percent}...";
  print $_;
}

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to