I find that this code is really all i need to read a file in. cat env.ini
[DB] # PRISM PROD PRISMSID = XX PRISMSVER = X.XX.com PRISMUSER = X PRISMPASS = X PRISMPRT = 1522 [EMAIL] # EMAIL for the program emailSENDER = xxx@xxx.com emailRECIPIENTS = xxx@xxx.com,xxx@xxx.com ADDITIONAL_EMAIL = xxx@xxx.com # EMAIL for DIGITAL PRINT ACTIVATION_FILE_SENDER=xxx@xxxx.com ACTIVATION_FILE_MAIL_LIST= ACTIVATION_MAIL_SUBJ=(PROD) | DAILY DIGITAL PRINT ORDERS [PATHS] RETURNFILE=/mnt/pcard/Return RETURNFILEWIN=\\xxxx\pcard\Return
Snippet of code
sub getConfig { my $file = shift(@_) ; my $function = ( caller(0) )[3] ; print "$function \n" ; # get the script .ini file my $script = basename($0); $script =~ s/\.\///; $script =~ s/pl$/ini/; my @files = ("env.ini", "config/$script") ; foreach my $file (@files) { unless ( -f $file ) { print "Could not find $file.\n" ; next ; } print "Config File : $file\n"; open(FH , "< $file"); my @array = <FH>; close FH; my $group = 'default'; foreach my $line (@array) { chomp($line); next if ( $line =~ /^\s*\#/); if ($line =~ /^\[\w+\]$/){ $line =~ s/\[//g; $line =~ s/\]//g; $line =~ s/\s*//g; $group = $line; print "Found group : $group \n"; }else{ next unless ($line =~ /=/) ; my ( $key, $variable ) = split( /=/, $line, 2 ) ; $variable =~ s/\s+//g ; $key =~ s/\s+//g ; $ref->{$group}->{$key} = $variable; } } } return; }
Outputs
$VAR1 = { 'CLIENT' => 'X', 'DB' => { 'PRISMPASS' => 'X', 'PRISMPRT' => 'X', 'PRISMSID' => 'X', 'PRISMSVER' => 'X', 'PRISMUSER' => 'XX' }, 'EMAIL' => { 'emailRECIPIENTS' => 'xxx@xxx.com,xxx@xxx.com' +, 'emailSENDER' => 'xxx@xxx.com' }, 'PATHS' => { 'RETURNFILE' => '/mnt/pcard/Return', 'RETURNFILEWIN' => '\\\\xxx\\pcard\\Return' }, 'config' => { 'Date' => '20141212', 'ENV' => 'PROD' } };

In reply to Re: Lots and lots of arguments! by crusty_collins
in thread Lots and lots of arguments! by zeltus

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.