Andrew Gaffney wrote:

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 $_;
}

First of all, using foreach will _always_ wait for all of the data before doing anything else, no matter what, so first change:


foreach (<MAKE>) {

to:

while (<MAKE>) {

and then try to find out if maybe it is indeed being buffered, though $| won't help you here, as it sets autoflushing on output, not input.

Another thing is that "make" is probably going to print much more lines than "make -n" because "make -n" only prints the commands to be executed while those commands themselves are likely to produce some output as well, unless all of them are run with >/dev/null 2>&1 at the end.

Try running this program:

#!/usr/bin/perl

use strict;
use warnings;

$| = 1;
my $total = `make -n | wc -l`;
my $count = 0;
open MAKE, "make 2>/dev/null |" or die "Can't open MAKE pipe";
while (<MAKE>) {
  $count++;
  my $percent = int(($count / $total) * 100);
  print "$percent%\r";
}
print "Done.\n";
__END__

Does it work? Keep in mind that unless every command in your Makefile ends with >/dev/null you will get values greater than 100%.

--
ZSDC


-- 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