in reply to File append not working. Any help?

Hi, I've a file which is opened for writing and then i close it. Again i open the same file for appending to its contents, but its not appending, its removing the older contents and freshly starting. Any help on whats the issue?

How do you know its not appending? Where do you check to see if its appending in your code?

This won't go to the log  system("pwd");

Also,

Um, no

$tme=localtime(); my ($d,$m,$y) = (localtime)[3,4,5]; my $mdy1 = sprintf '%d-%d-%d', $d, $m+1, $y+1900; print "\nDate is:$mdy1\n"; if ($mdy1 eq "0-3-2015") {$mdy1 = "28-2-2015";} print "\nDate is:$mdy1\n";

Um, yes

#!/usr/bin/perl -- use strict; use warnings; use Path::Tiny qw/ path /; use Time::Piece qw/ localtime /; use Data::Dump qw/ dd /; my $date = localtime()->strftime("%m-%d-%Y"); my $logprefix = "7252_Widevine_OemCrypto_Consolelog_User1"; my $logfile = $logprefix.'_'.$date.'.txt'; for my $ix ( 0 .. 3 ){ my $fh = path( $logfile )->opena_raw; print $fh "$ix\n"; close $fh; dd( path( $logfile )->slurp_raw ); } __END__ "0\n" "0\n1\n" "0\n1\n2\n" "0\n1\n2\n3\n"

Replies are listed 'Best First'.
Re^2: File append not working. Any help?
by ramki067 (Acolyte) on Jun 09, 2015 at 08:20 UTC
    Hi Anonymous Monk, I did try your code, but its still not working. To answer your Q on how to check if its appending or not, I have a sleep command after opening the file for appending. Within that sleep, if i check the contents of the file, all contents are vanished! and it continues to write as if to a new file after the append statement. Any help. Thanks,

      Hi Anonymous Monk, I did try your code, but its still not working.

      what do you mean by that?

      To answer your Q on how to check if its appending or not, I have a sleep command after opening the file for appending. Within that sleep, if i check the contents of the file, all contents are vanished!

      Are you sure it had contents at any point?