Spreading your code out among several different files won't
really clean up your code ... it will just spread it out
among several different files. :)
What you need to do is search the CPAN for some modules that
will make your task easier ... modules like
DBIx::Connect which will allow you to abstract the
DB connect info out of your scripts (and into a config
file). However, before i start ripping my one script into
a modularized, maintainable package ... i'd clean up what
you have. Here is how i would code your snippet:
my $dbh = DBI->connect(
qw(DBI:Oracle: user pass),
{RaiseError => 1},
);
# with RaiseError turned on, no need for die and errstr
$dbh->do("truncate table directory_data");
my $sth = $dbh->prepare(q{
INSERT INTO directory_data(
dn, cn, surname, given_name, initials,
generational_qualifier, building, room_number,
mailstop, telephone, fax, mail, tfs_id, uid
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)
});
$sth->execute($employee{$_},.,....) for keys %employee;
Sometimes i like to use code to generate an INSERT
statement:
my @field = qw(
dn cn surname given_name initials
generational_qualifier building room_number
mailstop telephone fax mail tfs_id uid
);
my $table = 'directory_data';
my $sql = "insert into $table ("
. join(',', @field)
. ') values ('
. join(',', map '?', @field)
. ')'
;
You could turn that snippet into a subroutine and pass it
the name of the table, an reference to an array of field
(column) names, and a reference to another array that
contains the values (just make sure the two arrays line
up!).
Hope this helps and gives you some ideas. :)
jeffa
L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)
|