Re: Puzzled by ouput from this script
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
Re: Puzzled by ouput from this script
On Wed, Sep 11, 2013 at 5:04 PM, Harry Putnam wrote: > while(<$cmdh>) { > print $fh; > print; > I believe this code prints the file handle. Try this: while(<$cmdh>){ print $fh $_; print; -- Robert Wohlfarth
Re: Make a sub routine return
Harry Putnam writes: Jesus... who wrote this illiterate crud? > Harry Putnam writes: > > Sorry to have dropped out on this. I called away and now have other ^ got > scripting to get done. > > But didn't want anyone to think I didn't appreciate the replies. > > The walk thru of my (poor) could is very helpful... -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Puzzled by ouput from this script
Posted below is a shortened down version of a larger script that tries to show the phenomena I'm seeing and don't understand. I'm running rsync from a perl script so I first thought the output was from rsync, but as I tinkered around I began to notice that as I changed things around a bit, the lines that puzzled me disappeared. I couldn't discover what it was I changed and lost track. Output from rsync shows this at the start of every line: `GLOB(0x8117548)' But just to show that its coming from perl; if I pass the content of ($_) to a variable ($line) the prepended data disappears... (You may note that bit commented out below) So, the code as shown below prepends 'GLOB(0x8117548)' to every line of outpout. ---- ---=--- - #!/usr/local/bin/perl use strict; use warnings; use File::Which; my $dst = '/rmh/m2/phonepics'; my $src = 'harry@m2:/cygdrive/d/ImagesMusic/ImageDB/images/imageArch/00inc/phonepics'; my $exclf = '/rmh/m2/x-scr/exclf'; my $longargs = "--stats --exclude-from=$exclf"; my $shortargs = '-navz'; my $rsync = which('rsync'); my $dtf = 'yymmdd_hhmmss'; my $log = './log/rsy.log'; 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>: $!"; #my $line; while(<$cmdh>) { print $fh; print; # $line = $_; # print $fh $line; # print $line; } close $cmdh; close $fh; sub usage { print " Purpose: usage: " } ---- ---=--- - Output: [...] GLOB(0x81573f8)samgalaxn2_phone/pswrk/done/20130905_095712.jpg GLOB(0x81573f8)samgalaxn2_phone/pswrk/done/20130905_100306.jpg GLOB(0x81573f8)samgalaxn2_phone/pswrk/done/20130905_100312.jpg [...] -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Puzzled by ouput from this script
Robert Wohlfarth writes: > On Wed, Sep 11, 2013 at 5:04 PM, Harry Putnam wrote: > > >> while(<$cmdh>) { >> print $fh; >> print; >> > > > I believe this code prints the file handle. Try this: > while(<$cmdh>){ > print $fh $_; > print; Egad! Yes, that is what's happening... thanks. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Make a sub routine return
Harry Putnam writes: Sorry to have dropped out on this. I called away and now have other scripting to get done. But didn't want anyone to think I didn't appreciate the replies. The walk thru of my (poor) could is very helpful... Thanks -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/