Ok, so I've gotten this far. This code listed below will allow the updates and pulls the current information from the second database, but, instead of modifying the current information in the database it creates a new record with the same ID. How can change this code to modify the record rather than add a new one?
$db_file_name = $tickets_db;
$in{'ID2'} = $rec{'Ticket'};
$ticket = $rec{'ID'};
open (DB, "<$db_file_name") or &cgierr("error in modify_records. unable to open db file: $db_file_name.\nReason: $!");
@lines = <DB>; # Slurp the database into @lines..
close DB;
$found = 0; # Make sure the record is in here!
LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; } # Skip and Remove blank lines
if ($line =~ /^#/) { $output .= $line; next LINE; } # Comment Line
chomp ($line);
@data = &split_decode($line);
if ($data[$db_key_pos] eq $in{'ID2'}) {
%in = &get_record($in{'ID2'});
$in{'Work'} = $rec{'Work'} . "," . $ticket;
$in{'ModifyDate'} = &get_date;
$output .= &join_encode(%in);
$found = 1; } }
open (DB, ">>$db_file_name") or &cgierr("error in add_record. unable to open database: $db_file_name.\nReason: $!");
print DB $output;
close DB; # automatically removes file lock
@db_cols = @work_cols;
$db_file_name = $work_db;
Code:
@db_cols = @tickets_cols; $db_file_name = $tickets_db;
$in{'ID2'} = $rec{'Ticket'};
$ticket = $rec{'ID'};
open (DB, "<$db_file_name") or &cgierr("error in modify_records. unable to open db file: $db_file_name.\nReason: $!");
@lines = <DB>; # Slurp the database into @lines..
close DB;
$found = 0; # Make sure the record is in here!
LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; } # Skip and Remove blank lines
if ($line =~ /^#/) { $output .= $line; next LINE; } # Comment Line
chomp ($line);
@data = &split_decode($line);
if ($data[$db_key_pos] eq $in{'ID2'}) {
%in = &get_record($in{'ID2'});
$in{'Work'} = $rec{'Work'} . "," . $ticket;
$in{'ModifyDate'} = &get_date;
$output .= &join_encode(%in);
$found = 1; } }
open (DB, ">>$db_file_name") or &cgierr("error in add_record. unable to open database: $db_file_name.\nReason: $!");
print DB $output;
close DB; # automatically removes file lock
@db_cols = @work_cols;
$db_file_name = $work_db;