Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hi Monks, I have been following Perl since 1 month, looks interesting. Now, I have a trouble some requirement. 1. read all .log files in a folder (output of Jmeter execution which are basically XML with .log extention) 2. Search for keywords like 2.a. httpSample's attribute value by key lb 2.b. content of failure, error and errormessage tags 3. Print them as report to HTML so that I can send as email Here is the code I have:

#!/usr/lib/perl use strict; use warnings; use Carp; use File::Find; use XML::Parser; use File::Spec::Functions qw( canonpath ); my $failureMessage = ""; my $failure = ""; my $error = ""; my $value = ""; my $element = ""; #chomp $element; if ( @ARGV == 0 ) { push @ARGV, "C:\\Users\\bijoymeethal\\Desktop\\xml test"; warn "Using default path $ARGV[0]\n Usage: $0 path ...\n"; } open(HTML_FILE, ">BAT_Report.html") || die "Can't open file: $!\n" +; # Print the initial HTML tags print HTML_FILE "<html>\n<body>\n<h1>BAT Report - JMeter Test</h1>\n<h +r><br><table class=MsoTableGrid border=1 cellspacing=0 cellpadding=0 +><tr><th><p>TestPlan</p></th><th><p>Test Failed?</p></th><th><p>Failu +reMessage</p></th><th><p>Link to Source</p></th></tr>"; find( sub { return unless ( /[.]log\z/i and -f ); extract_information(); return; }, @ARGV ); sub extract_information { my( $expat, $element, %attrs ) = @_; #my $line = $expat->current_line; if ($element eq "httpSample") { if( %attrs ) { while( my( $key, $value ) = each( %attrs )) { if ($key eq "lb"){ print "\t$key => $value\n"; } } } }elsif ($element eq "failure"){ $failure = $element; }elsif ($element eq "error"){ $error = $element; }elsif ($element eq "failureMessage"){ $failureMessage = $element; } print HTML_FILE <<"EOF"; <tr><td><p>$value</p><td><p>$failure</p></td><td><p>$failureMessage</p +></td></tr> EOF return; } print HTML_FILE "</body><br></html>"; close (HTML_FILE);

I need help to correct this to the requirement and suggestions.

Use of uninitialized value $element in string eq at XMLGrouper_tr1.pl +line 37. Use of uninitialized value $element in string eq at XMLGrouper_tr1.pl +line 45. Use of uninitialized value $element in string eq at XMLGrouper_tr1.pl +line 47. Use of uninitialized value $element in string eq at XMLGrouper_tr1.pl +line 49.

In reply to trouble,, need help! by numberuno

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (1)
As of 2024-04-19 00:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found