On 11/09/2013 23:04, Harry Putnam wrote:

Posted below is a shortened down version of a larger script that tries
to show the phenomena I'm seeing and don't understand.

open my $fh, '>>', $log  or die "Can't open <$log>: $!";
print " $dtf START $rsync $shortargs\n   $longargs\n      $src/ $dst/\n\n";
open my $cmdh, '-|', "$rsync $shortargs $longargs $src/ $dst/" or die "ERROR running 
<$rsync>: $!";

while (<$cmdh>) {
   print $fh;
   print;
}

The problem is with the line `print $fh`. I presume you intend it to
print the contents of $_ to the file handle $fh. Unfortunately that
isn't the guess that Perl makes: it assumes you want to print the
*value* of $fh to file handle STDOUT. Fix it by writing

    print $fh $_;

I also suggest that you don't write multi-line output with a single
print statement like that. It is much clearer written as

    print " $dtf START $rsync $shortargs\n";
    print "   $longargs\n"
    print "      $src/ $dst/\n\n";

or you could use a "here document" and write it like this

print <<END;
 $dtf START $rsync $shortargs
   $longargs
      $src/ $dst/

END

but you have to be very careful with indentation if you do that, as
leading and trailing space is significant, and Perl will be looking for
a line that contains *exactly* `END`, with no spaces before or after it.
Note that you can use any string you like instead of `END`; the only
condition is that the characters after `<<` must exactly match the line
that terminates the string.

HTH,

Rob


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to