in reply to Writing to File based on condition
Hi, you are trying to read from the file while you have it open for writing. You should read the current values, then do your processing, then open for writing (if you have anything to write).
Update: I don't believe you are reading from the file with "+>>", now that I test it:
Output:$ perl -MPath::Tiny -Mstrict -Mautodie -wE ' my $file = Path::Tiny->tempfile; open my $FH, ">", $file; print $FH "$_\n" for qw/foo bar baz/; close $FH; open my $FH2, "<", $file; print "2: $_" while (<$FH2>); close $FH2; open my $FH3, "+>>", $file; print "3: $_" while (<$FH3>); print $FH3 "I was here"; close $FH3; open my $FH4, "<", $file; print "4: $_" while (<$FH4>); close $FH4; '
2: foo 2: bar 2: baz 4: foo 4: bar 4: baz 4: I was here
Hope this helps!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Writing to File based on condition
by cbtshare (Monk) on Feb 17, 2018 at 04:34 UTC |