Carlo Filippini wrote:
> Hi
> I try to measure how fast an ftp download is going on the
> fly. I do something like:
>
> $|=1;
> my $count =0;
> open (CMD, "ftp.script 2>&1 |") or die "Can't execute: $!";
> while (<CMD>){
> print "Result: $_ \n";
> if ($_ =~ /\#/) {
> $count ++;
>
> }
>
> Thanks
> Carlo
I suspect the ftp.script output is not putting end-of-line characters at
the end of lines, so you may have to use the perl read command instead
of <CMD>. For example, you put (reference: perldoc -f read)
read CMD,$char,1
if you want to read one character at a time into the scalar $char. And
then you can test for '#' as you were doing. So you can try (I haven't
tested this):
$|=1;
my $count =0;
my $char;
open (CMD, "ftp.script 2>&1 |") or die "Can't execute: $!";
print "Result: ";
while (read CMD,$char,1){
print $char;
if ($char =~ /\#/) {
$count ++;
print "\nResult:";
}
if ($char =~ /\r|\n/) {
print "\nResult: "
} # for Windows, this may give extra blank lines
}
Boyd
|