Try the following script. I haven't tested it, but it should work okay.
# -------------------------------------------
$ENV{'REQUEST_METHOD'} and (print "Content-type: text/plain\n\n");
open (DB, "<links.db") or
print "Unable to open links database 'links.db'. Reason: $!" and exit;
print "\tOpening output file . . .\n";
open (DBOUT, ">links2.db") or
print "Unable to open output database.
Make sure data dir is chmod 777 temporarily. Reason: $!" and exit;
print "\tProcessing records\n";
while (<DB> ) {
/^#/ and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp; # Remove trailing new line.
@rec_in = &split_decode($_);
# Copy ID, Title, URL, Date and Category
for $i (0 .. 4) {
$rec_out[$i] = $rec_in[$i];
}
# Add New Field here
$rec_out[5] = ""; # add something between quotes if you have a default value
# Copy the rest of old links.db to new links2.db
for $i (5 .. 13) {
$rec_out[$i + 1] = $rec_in[$i];
}
print DBOUT &join_encode(&array_to_hash(0, @rec_out));
}
print "\tDone.\n\n";
close DB;
close DBOUT;
print "Database saved it as links2.db.\n";
print "Change permissions back to 755 on the data directory.\n\n";
print "You must rename 'links2.db' to 'links.db before using with Links v2.\n";
print "It is recommend you save the original 'links.db' before renaming.";
You can adjust the range in the two "for" loops and the field being added if the field numbers are different in your case.
I hope this helps.
[This message has been edited by Bobsie (edited March 30, 1999).]
Code:
#!/usr/local/bin/perl # -------------------------------------------
$ENV{'REQUEST_METHOD'} and (print "Content-type: text/plain\n\n");
open (DB, "<links.db") or
print "Unable to open links database 'links.db'. Reason: $!" and exit;
print "\tOpening output file . . .\n";
open (DBOUT, ">links2.db") or
print "Unable to open output database.
Make sure data dir is chmod 777 temporarily. Reason: $!" and exit;
print "\tProcessing records\n";
while (<DB> ) {
/^#/ and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp; # Remove trailing new line.
@rec_in = &split_decode($_);
# Copy ID, Title, URL, Date and Category
for $i (0 .. 4) {
$rec_out[$i] = $rec_in[$i];
}
# Add New Field here
$rec_out[5] = ""; # add something between quotes if you have a default value
# Copy the rest of old links.db to new links2.db
for $i (5 .. 13) {
$rec_out[$i + 1] = $rec_in[$i];
}
print DBOUT &join_encode(&array_to_hash(0, @rec_out));
}
print "\tDone.\n\n";
close DB;
close DBOUT;
print "Database saved it as links2.db.\n";
print "Change permissions back to 755 on the data directory.\n\n";
print "You must rename 'links2.db' to 'links.db before using with Links v2.\n";
print "It is recommend you save the original 'links.db' before renaming.";
You can adjust the range in the two "for" loops and the field being added if the field numbers are different in your case.
I hope this helps.
[This message has been edited by Bobsie (edited March 30, 1999).]