Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^2: Debugging PAR packaged programs

by wanna_code_perl (Pilgrim)
on Dec 09, 2008 at 17:34 UTC ( #729216=note: print w/replies, xml ) Need Help??

in reply to Re: Debugging PAR packaged programs
in thread Debugging PAR packaged programs

Nothing immediately obvious comes to mind. In cases like this, often the simplest solution is to instrument the code with some simple debug statements.
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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://729216]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2016-10-01 12:53 GMT
Find Nodes?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:

    Results (576 votes). Check out past polls.