peewee_zz has asked for the wisdom of the Perl Monks concerning the following question:
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.# __/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 #|_________________________________
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Overwrite a file (delete a file 2. Revenge of the Sith)
by shmem (Chancellor) on Oct 11, 2006 at 17:25 UTC | |
by peewee_zz (Initiate) on Oct 11, 2006 at 17:37 UTC | |
|
Re: Overwrite a file (delete a file 2. Revenge of the Sith)
by ysth (Canon) on Oct 11, 2006 at 17:26 UTC | |
by peewee_zz (Initiate) on Oct 11, 2006 at 17:36 UTC | |
|
Re: Overwrite a file (delete a file 2. Revenge of the Sith)
by blue_cowdawg (Monsignor) on Oct 11, 2006 at 17:21 UTC |