If you know about reading and writing Perl files, try reading in the whole file, changing the part you want to change, then writing the whole file back to update it. Like this:
But, keep in mind that although something like this works fine for tiny files it doesn't scale well, so if your file gets bigger later, or needs to be accessed lots and lots of times (multiple times per second) you should look into more flexible solutions like a tied hash (SDBM, NDBM, GDBM and siblings) or a full-bore database like MySQL or PostgreSQL.# Load in the whole file open (FILE, "memberpoints.txt") or die "Can't read: $!"; while (<FILE>) { chomp; ($name, $number) = split "-"; $field ($name) = $number; } # Change whatever you want $field{'vegeta'} += 6; # ..etc # Write the whole file back (replacing what was there before) open (FILE, ">memberpoints.txt") or die "Can't write: $!"; foreach (keys %field) { print FILE "$_-$field{$_}\n"; }
Gary Blackburn
Trained Killer
Edited: Forgot to chomp the newline. Bad newline. Bad. Added the chomp in.
In reply to Re: Editing files...please help
by Trimbach
in thread Editing files...please help
by tanger
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |