Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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.


Comment on Re^2: Debugging PAR packaged programs
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2014-08-30 23:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls