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.
|