I think Perl Best Practices recommends the module AppConfig.pm (Available through CPAN and also PPM if you're using Active State). I was curious if a solution could be reached that way; this is an implementation of AppConfig for this kind of problem.

The config file is named email.conf and contains:

# # My email configuration file # pro_box = 1 [pro_box] emails = person1@mycompany.com emails = person2@mycompany.com emails = person3@mycompany.com emails = person4@mycompany.com [default] emails = person2@mycompany.com emails = person3@mycompany.com emails = person4@mycompany.com
And the code to handle it is:

#!/usr/bin/perl use warnings; use strict; use AppConfig qw( :argcount ); my $config = AppConfig->new( {CREATE => 1, GLOBAL => { ARGCOUNT => ARGCOUNT_LIST }, }); my $config_file = "email.conf"; $config->define("pro_box", { ARGCOUNT => ARGCOUNT_ONE } ); $config->file($config_file); # # Fetch pro box value # my $pro_box = $config->pro_box; # # Fetch arrays. Get rid of the "1" in @array[0]. # my @pro_emails = @{$config->pro_box_emails}; shift @pro_emails; my @default_emails = @{$config->default_emails}; shift @default_emails; print "Pro Box = $pro_box \n"; print "\n" ; my @mail_to = ($pro_box) ? @pro_emails : @default_emails ; for (@mail_to ) { print "My addresses are: $_ \n"; }
The output from the code is:

C:\Code>perl test_app_config.pl Pro Box = 1 My addresses are: person1@mycompany.com My addresses are: person2@mycompany.com My addresses are: person3@mycompany.com My addresses are: person4@mycompany.com

In reply to Re: External Array of Emails by dwm042
in thread External Array of Emails by Anonymous Monk

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.