You might consider moving many of those variables (ftp host, ftp user, email address, log directory, etc) into a configuration file. That would allow you to change these values in the future, without touching the source code. The config file could even be located in a place where your operations staff (if you have one) can modify it, allowing them to do things like update an email address without involving you at all.

I like to use Config::IniFiles (available on CPAN) for this purpose. I generally tie it to a hash, reducing the number of global variables that I have to keep track of.

Here's a sample config.ini file. It has separate values for testing and production, making it easy to switch from one to the other:

[prod] ftp_host = ftp.uslec.net ftp_user = cheese ftp_pass = whiz log_method = both def_email = someone@somewhere.com LOGFILE = /u20/home/gvc/log/something.log [test] ftp_host = ftp.uslec.net ftp_user = cheesetest ftp_pass = whiztest log_method = both def_email = someonetest@somewhere.com LOGFILE = /u20/home/gvc/log/somethingtest.log

Here's a sample code snippet:

use Config::IniFiles; our (%cfg); my %ini; tie %ini, 'Config::IniFiles', (-file => "config.ini"); %cfg = %{$ini{'prod'}}; print "I will FTP files to" . $cfg{ftp_host};

Wally Hartshorn


In reply to Configuration File by Wally Hartshorn
in thread Compress and FTP files by gnu@perl

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.