To update a file, you open it for reading, read line by line,
update the line, and write the line out to a new file. Assume
the @table holds the data to add. Then you could use something
like
open OLD, "<old.txt"
or die "Could not open old.txt: $!";
open NEW, ">new.txt"
or die "Could not open new.txt: $!";
my $i = 0;
while (<OLD>) {
chomp;
$_ .= $table[ $i++ ];
print NEW "$_\n";
}
close OLD;
close NEW;
Nota bene: it is better to entitle your questions with
something more descriptive than "file", say, "Editing a file
in place", or "Updating a flat file database".
-Mark | [reply] [d/l] |