You might want to spend some time in the Tutorials section. There's a lot of good information for beginners.

Strict is useful for helping Perl help you catch simple mistakes. (That's a bit of a simplification, but it makes the point.) Without seeing your code, I can only guess why you feel it makes your code long. Have you considered that you can use "my" with multiple variables at once as long as you put them in parentheses as a list? And you can assign to it all at the same time, too:

my ($foo, $bar, $bam); # or my ($foo, $bar, $bam) = qw/ red green blue /;

For configuration variables, while you can do that "by hand", there are many, many CPAN modules to make your life easier. For very simple configuration variables, I'd suggest starting with Config::Tiny.

In config.ini:

var1 = blah var2 = 23

In your code:

use Config::Tiny; # Open the config my $config = Config::Tiny->read( 'config.ini' ); my $config_hash = $Config->{_}; print "Var 1: ", $config_hash->{var1}; # You can also change and save the config again $config_hash->{var2} = 42; $config->write( 'config.ini' );

I think you'll find that much easier than trying to write something yourself. (You'll need to install Config::Tiny from CPAN, of course.)

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.


In reply to Re: Perl configuration files by xdg
in thread Perl configuration files by rbnorthcutt

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.