My suggestion would be to break this out into 2-3 different modules, each of which would be used by the scripts that need that functionality. Right now, it looks like you have two different functionalities - database connectivity and filelists. So, I would do something like:
# In file Database.pm package Database; our @ISA = qw(Exporter); our @EXPORT_OK = qw( DB_connect DB_disconnect ); use DBI; my %config = ( type => 'mysql', name => 'SUN', ); sub DB_connect { # Allow the user to override anything they want to in %config %config = (%config, @_); my $connect_string = join(':', 'DBI', $config{type}, $config{name}, ); my $dbh = DBI->connect( $connect_string, $config{user}, $config{password}, $config{options}, ); unless ($dbh) { die "Cannot open connection to $connect_string with $config{us +er} / $config{password}\n" . DBI->errstr, $/; } return $dbh; } sub DB_disconnect { my ($dbh) = @_; $dbh->disconnect if UNIVERSAL::isa($dbh, 'DBI'); return 1; } 1;

You can do something similar with your files. Now, you have connecting to a database abstracted out into something you can reuse.

------
We are the carpenters and bricklayers of the Information Age.

The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.


In reply to Re: variables / consts for different scripts by dragonchild
in thread variables / consts for different scripts by Skeeve

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.