while(<CONFIG_FILE>) { print("Line: $_\n"); if(/^backup path\s*=/) { (undef, $backupPath) = split(/\s*=\s*/,$_); } elsif(/^activation code\s*=/) { (undef, $activationCode) = split(/\s*=\s*/,$_); print "activation code: $activationCode\n"; } # etc...
If you see the "activation code=" line, but your following $activationCode print doesn't show, then you know you have a parsing problem. If you never see the "activation code=" line at all, perhaps you're somehow missing reading the first line of the file.
Anyway, even in the absence of external modules, this ugly code could have been made cleaner and less error prone with something like this:
my %config; foreach (<CONFIG_FILE>) { unless (/^\s*(.+?)\s*=\s*(.+?)\s*$/) { chomp($_); warn "Invalid config format: `$_'"; next; } $config{$1} = $2; }
This way, you don't pollute your global namespace with configuration variables, and you now have a 1:1 mapping between configuration variable names and hash keys, which has got to be easier to remember and maintain.
You should still definitely have additional error checking and some validation checks after the file is read.
In reply to Re^2: Debugging PAR packaged programs
by wanna_code_perl
in thread Debugging PAR packaged programs
by dirtdart
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |