Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Not able to replace to directory paths

by Anonymous Monk
on Mar 10, 2011 at 22:26 UTC ( [id://892554]=note: print w/replies, xml ) Need Help??


in reply to Re: Not able to replace to directory paths
in thread Not able to replace to directory paths

I have a interesting problem now,the below code dumps "$stdout" output of the $cmd command run to "p4diff.log",what I noticed is it's not entering the while loop if I do this where as if I use a pre-existing p4diff.log without generating through the program it enters the program,any idea what could be wrong in the below code

$cmd = [ (qw(p4 diff -f -sl), $options{v}) ]; run3($cmd, \$stdin, \$stdout, \$stderr); #print "\n$stderr\n"; #Output the diff to p4diff.log open(my $P4DIFF, '+>', "p4diff.log") or die $!; print $P4DIFF $stdout; $input = <p4diff.log>; #Open teh p4diff.log to get the missing files and output to dele +tefiles.txt open(my $OUTPUT, '+>', "deletefiles.txt") or die $!; open my $DATA, '<', $input or die "could not open '$input' $!"; while ($line = <$DATA>) { print "IN WHILE LOOP\n";#not printing if ($line =~ /missing/) { $line =~s/\\/\//g; $line =~s/\Q$client_root\E/$perforce_root_dir/g; print "$line\n"; print $OUTPUT $line; } } close $OUTPUT;

Replies are listed 'Best First'.
Re^3: Not able to replace to directory paths
by Eliya (Vicar) on Mar 10, 2011 at 23:26 UTC

    Maybe you should close $P4DIFF before you open the associated file?

    Depending on how much you've written, the IO buffer (size 4k) might not have been flushed yet, so the file behind $DATA could be empty.  In other words, you'd get EOF with the loop quitting right away...

    This doesn't print anything (i.e. while loop not entered):

    open(my $P4DIFF, '+>', "p4diff.log") or die $!; print $P4DIFF "foo\n" x 3; # close $P4DIFF; my $input = "p4diff.log"; open my $DATA, '<', $input or die "could not open '$input' $!"; while (my $line = <$DATA>) { print ">> $line"; }

    while if you uncomment the close, you'd get:

    >> foo >> foo >> foo
Re^3: Not able to replace to directory paths
by GrandFather (Saint) on Mar 10, 2011 at 22:53 UTC

    What does $input contain? What do you expect it to contain? What does the file of the name in $input contain? Why are you not using strictures?

    True laziness is hard work

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://892554]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-26 00:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found