in reply to Re: Text file got corrupted?
in thread Text file got corrupted?
Please help me look at the code to see if I'm missing something :)# When I test the script locally in Windows, I need # to suppress flock because it's not supported # In use in the server, $flock is set to 1. my $flock = 1; sub modify { my $tmp_file = get_file(); open(FILE,"+<$tmp_file") || error("The file $tmp_file cannot be foun +d!"); flock(FILE, 2) || die $! if $flock; chomp(my @lines = <FILE>); seek(FILE,0,0); truncate(FILE,0) || die $!; # could have used foreach here for (0..@lines) { my ($name, $score) = split/\|/, $lines[$_]; $score++; print FILE "$name|$score\n" if ($name); } close FILE; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Text file got corrupted?
by jonnyfolk (Vicar) on Oct 01, 2003 at 07:47 UTC |