I am new to use strict, and tired of being flamed for not using it. so, I am attempting to write a script that... uses strict!
my problem lies with a variable scope that I cant figure out. On line 10 of the following script I have an "unless" statement. The script ran fine, untill I wrapped that line of code inside the unless. Once I wrapped it, I apparently lost scope of the $cfg variable... I tried replacing "my $cfg" with our, and local $cfg. Obviously neither of those worked.. What is the correct way to do this???
#!/usr/local/bin/perl -w
use strict;
use Config::Simple;
my $config_file = shift;
if (!$config_file) {
$config_file = "etc/allweb-backup.conf";
}
unless (my $cfg = new Config::Simple($config_file)) {
print "CRITICAL: $config_file is not a valid INI file!\n";
}
my %Config = $cfg->vars();
print "###############################################\n-CONFIG-: $con
+fig_file\n";
while (my($key,$val) = each %Config) {
if (!$val) {
print "WARNING : $key has NULL value!\n";
my $count++;
}else {
print "OK : $key has value of $val\n";
}
}
print "#########################################\ndone.\n";
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.