in reply to Appending to filenames, system mv, using MIME::Lite and other fun

I have 8 csv files that need to be archived and emailed to 8 different addresses once a day
Explain this a bit more? You have 8 CSV files -- do they all go to each of the 8 addresses, or is there a correspondence between each CSV file and a particular address?

For example, let's say the CSV files are named a.csv, b.csv, et cetera. Your first recipient is john_q_public@foobar.com. Does he get all 8 csv files? Only a.csv? Some subset (i.e., John needs a.csv, d.csv, and f.csv, but no others)? The answer to that will change how to approach the hash.

Unrelated to the hashes, you can simplify part of your code. Specifically, the sys_date sub can be replaced by POSIX::strftime. At the top of your script add use POSIX then the sys_date sub call can be replaced with something like:
$file_date = POSIX::strftime("%b%d%Y", localtime);

See strftime docs for all of the available formats.

Replies are listed 'Best First'.
Re^2: Appending to filenames, system mv, using MIME::Lite and other fun
by hmbscully (Scribe) on Jul 26, 2005 at 21:29 UTC
    Obviously that makes a huge difference. There is a correspondence between each file. One file goes to one address. Thanks for the POSIX suggestion. I'll give that a try.
      In that case you can create a simple lookup. Something akin to (using my previously named examples):

      my %csv_recipients = ( 'john_q_public@foobar.com' => 'a.csv', 'jane_q_public@xyz.com' => 'b.csv', 'some_other_address@example.com' => 'c.csv' # and so on );

      Then to send it out just change your call to archive_results:

      while (my ($recipient, $filename) = each %csv_recipients) { archive_results($recipient, $orig_file, $filename, $subject); }
      or similar. Code untested, void where prohibited by law, et cetera et cetera ad nauseum.