Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Parsing a file.. having trouble.

by Everlong (Initiate)
on May 05, 2017 at 23:13 UTC ( [id://1189629]=perlquestion: print w/replies, xml ) Need Help??

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:

    foreach $testfailure ($test->findnodes('./failure')) { $failure_type = $testfailure->getAttribute('type +'); $failure_temp = $testfailure->getAttribute('mess +age'); } foreach $testpassed ($test->findnodes('./skip')) { $failure_type = $testfailure->getAttribute('type +'); $failure_temp = $testfailure->getAttribute('mess +age'); }

    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:

    foreach $testpassed ($test->findnodes('./skip')) { $failure_type = $testpassed->getAttribute('type' +); # ^^^^^^^^^^^ $failure_temp = $testpassed->getAttribute('messa +ge'); # ^^^^^^^^^^^ }

    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:

    if ($error_type ne '') { ... } elsif ($failure_type ne '') { ($failure_message, $junk) = split(/^/, $failure_temp, 2); chomp $failure_message; $failure_message =~ s/,/|/g; print OUTFILE "FAILED, $failure_type, $failure_message\n"; } elsif ($failure_type ne '') { ... $failure_message =~ /skip/; print OUTFILE "SKIPPED, $failure_type, $failure_message\n"; } else { print OUTFILE "PASSED\n"; }

    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,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re: Parsing a file.. having trouble.
by NetWallah (Canon) on May 06, 2017 at 04:10 UTC
    Your code on github does not compile.

    This post does, and the problem seems to be duplication of this test:

    } elsif ($failure_type ne '') {
    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1189629]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-25 16:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found