Here's the code first off: (any variables not shown are global and declared at the begnning of the script)
# __/AddStatus\____________ #| #| sub AddStatus { my @tempfile_a; my $to_add; $to_add = param('txt_status') . "\n"; my $whichfile; my $breaksread; $breaksread = 1; my $linenum; $linenum = 0; if ($chosen > $opnum) { $chosen = $chosen - $opnum; $whichfile = "closed.dat"; } else { $whichfile = "open.dat"; } open (CASEFILE, $whichfile) or dienice ("Can't open file $whichfile" +); @readfile_a = <CASEFILE>; close(CASEFILE); foreach $line (@readfile_a) { #see if we're on a break $testline = substr($line, 0, 2); if ($testline eq "\$.") { #if so increase breaksread $breaksread = $breaksread + 1; } #if it's not a break then see if the line is in the entry elsif ($breaksread == $chosen) { if ($testline eq "\$e") { print "boooo $linenum - $to_add<br>\n"; @tempfile_a[$linenum] = $to_add; $linenum = $linenum + $linenum; } } @tempfile_a[$linenum] = $line; $linenum = $linenum + 1; } # $whichfile = ">b" . $whichfile; # print "$whichfile<br>\n"; print @tempfile_a; # create a lock file my $lockfile; $lockfile="lock_the_file.loc"; while (-e $lockfile) { sleep 2; } open (LOCK,">$lockfile") || die ("Cannot open lock file!\n"); close (LOCK); open (CASEFILE, ">$whichfile"); print CASEFILE @tempfile_a; close(CASEFILE); unlink($lockfile); } #| #| End AddStatus #|_________________________________
What happens is that it either selects and reads from closed.dat or open.dat and keeps that filename in $whichfile. Now it then stores the info into @readfile_a which then is read into @tempfile_a except adding a line. After this it opens the same $whichfile again for overwrite except that it does not make any changes. I print out the @tempfile_a and it shows that a change should be made but it will not overwrite the open.dat or closed.dat files. Now I tried changing the output file to ">bb$whichfile" and it creats bbopen.dat and everytime I update it, it will create a new file fine. Then I run the script again and it also overwrites the bbopen.dat file just fine. (meaning that it creates a file and then i run the same script again to overwrite that same file) It seems to be entirely file permissions which doesn't completely make sense but at least it's being consistant. Any file that I make by rightclick->new->textdocument will not allow me to overwrite but any file generated by perl will. So it's some kind of strange permissions situation. Should be as simple as getting down to this specific server and applying permissions.

In reply to Overwrite a file (delete a file 2. Revenge of the Sith) by peewee_zz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.