Hi,
In add.cgi where links.def is included, I would like to include some records form another database. I modified the script to read the other database, and assign the values. Only array_to_hash will usualy build the records of my job-database with the names of my links-database. (due to links.def)
So I assign the values like: $in{'JOBTITLE'} = $job{$db_cols[3]};
But I'm wondering the following:
- What if I would like to include a number (like: $job{$db_cols[16]}) thats higher then the number of records of my links-database?
- Can I modify array_to_hash so i would not try to build the array with names, but only with numbers; So I'm sure eveything will function normal!
Or am I already overriding the function by using $job{$db_cols[3]} instead of names; so I don't need to worry about anything?!
Hope someone can give me some feedback........
open (DB, "<$db_job_name") or &cgierr("error in dynamic_form. unable to open db file: $db_job_name. Reason: $!");
LINE: while (<DB>) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
chomp;
@data = &split_decode($_);
if ($data[0] eq $jobid) {
$found = 1;
%job = &array_to_hash (0, @data);
last LINE;
}
}
close DB;
$found or &display ("Unable to display record: $jobid") and return;
$in{'JOBTITLE'} = $job{$db_cols[3]};
# --------------------------------------------------------
# Converts an array to a hash using db_cols as the field names.
#
my ($hit, @array) = @_;
my ($i);
return map { $db_cols[$i] => $array[$hit * ($#db_cols+1) + $i++] } @_;
}
In add.cgi where links.def is included, I would like to include some records form another database. I modified the script to read the other database, and assign the values. Only array_to_hash will usualy build the records of my job-database with the names of my links-database. (due to links.def)
So I assign the values like: $in{'JOBTITLE'} = $job{$db_cols[3]};
But I'm wondering the following:
- What if I would like to include a number (like: $job{$db_cols[16]}) thats higher then the number of records of my links-database?
- Can I modify array_to_hash so i would not try to build the array with names, but only with numbers; So I'm sure eveything will function normal!
Or am I already overriding the function by using $job{$db_cols[3]} instead of names; so I don't need to worry about anything?!
Hope someone can give me some feedback........
Code:
open (DB, "<$db_job_name") or &cgierr("error in dynamic_form. unable to open db file: $db_job_name. Reason: $!");
LINE: while (<DB>) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
chomp;
@data = &split_decode($_);
if ($data[0] eq $jobid) {
$found = 1;
%job = &array_to_hash (0, @data);
last LINE;
}
}
close DB;
$found or &display ("Unable to display record: $jobid") and return;
$in{'JOBTITLE'} = $job{$db_cols[3]};
Code:
sub array_to_hash { # --------------------------------------------------------
# Converts an array to a hash using db_cols as the field names.
#
my ($hit, @array) = @_;
my ($i);
return map { $db_cols[$i] => $array[$hit * ($#db_cols+1) + $i++] } @_;
}