Everlong has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |||
|---|---|---|---|
|
Re: Parsing a file.. having trouble.
by Athanasius (Archbishop) on May 06, 2017 at 03:58 UTC | |||
Hello kalantal, and welcome to the Monastery! It looks to me as though the author of the script relied rather too heavily on cut-and-paste. For example, in this section:
the variable $testfailure first iterates over ‘failure’ nodes, but then — without being reinitialised — is accessed in the following foreach loop to find the failure type and message for ‘skipped’ nodes. I assume this is what was meant:
This is the sort of error that is easy to pick up if you have use strict; at the head of your code. You should always do this, and put use warnings; there as well. (Actually, the logic of this whole section of code looks highly dubious to me. It iterates over ‘failure’ nodes and sets $failure_type and $failure_temp once only, then iterates over ‘skipped’ nodes and overwrites the values of these variabes, and so on.) The problem you are seeing comes from a similar cut-and-paste error, but in this case it’s made harder to see by the way the code is formatted. Here is the skeleton of the problem section:
Can you see the problem now? The condition in the second elsif clause is identical to the condition in the first elsif clause, so the second one will never be true and the section dealing with skipped nodes will never be entered. You need to change the condition to catch the ‘skipped’ case. (I can’t tell you what the condition should be, as I don’t sufficiently understand how the script is supposed to be working.) Hope that helps,
| [reply] [d/l] [select] | ||
|
Re: Parsing a file.. having trouble.
by NetWallah (Canon) on May 06, 2017 at 04:10 UTC | |||
This post does, and the problem seems to be duplication of this test: You seem to have copy/pasted the same set of lines without setting separate variables to distinguish 'passed' from 'skipped'. Try 'perltidy' to improve code formatting, and if you find youself repeating very similar lines of code, consider subroutines. ...Disinformation is not as good as datinformation. Don't document the program; program the document. | [reply] [d/l] | ||