Gossamer Forum
Home : Products : Links 2.0 : Customization :

array_to_hash; the consequences

Quote Reply
array_to_hash; the consequences
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........


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++] } @_;
}
Subject Author Views Date
Thread array_to_hash; the consequences ds 3596 Mar 13, 2001, 5:39 AM
Thread Re: array_to_hash; the consequences
Stealth 3559 Mar 13, 2001, 9:02 AM
Thread Re: array_to_hash; the consequences
ds 3548 Mar 14, 2001, 12:41 AM
Thread Re: array_to_hash; the consequences
Stealth 3542 Mar 14, 2001, 8:26 AM
Thread Re: array_to_hash; the consequences
ds 3566 Mar 14, 2001, 10:16 AM
Post include 2 .def files
cK 3520 Mar 14, 2001, 2:44 PM
Thread Re: array_to_hash; the consequences
glennu 3510 Mar 15, 2001, 5:06 AM
Thread Re: array_to_hash; the consequences
ds 3482 Mar 15, 2001, 5:45 AM
Thread Re: array_to_hash; the consequences
sponge 3465 Mar 15, 2001, 10:18 AM
Thread Re: array_to_hash; the consequences
ds 3479 Mar 15, 2001, 11:16 AM
Post Re: array_to_hash; the consequences
cK 3458 Mar 15, 2001, 12:48 PM
Thread Re: array_to_hash; the consequences
sponge 3469 Mar 15, 2001, 9:06 PM
Post Re: array_to_hash; the consequences
ds 3442 Mar 16, 2001, 3:13 AM