Posted by ADnoctum on 2000-05-09
Hi,
I'm writing a perl script and I need to read an array from a file, change
one or two values and then write it to the same file again, for that I'm
using this code:
open FILE, "file.dat";
@array = <FILE>;
close FILE;
$array[$index]++;
open FILE, "+> file.dat"
foreach $tmp ( @array ) {
print FILE $tmp;
}
close FILE;
but after running the script a few times the file it looks like this:
0
110
0
111111110
0
110
0
0
..when the $index has been reset to 1,3,5,3,3,5,3,3,1,3,3,3, but the file
should look like this:
0
2
0
8
0
2
0
0
HEEELLLPPP!!!!!!! please.....
PS: If this is a dumb question let me know why. I'm just starting with
perl. =)
To signoff send a mail to listserver@xxxx.xx.xx with
"signoff tcg" in the body of your message.
Previous post | Next post | Timeline | Home