CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
group and print data seperately

 



techtween
Novice

May 24, 2011, 8:28 AM

Post #1 of 2 (346 views)
group and print data seperately Can't Post

I have an XML file of the form,

<?xml version="1.0" encoding="UTF-8"?>
<testResults version="1.2">
<httpSample t="704" lt="704" ts="1306146504248" s="true" lb="HTTP Request" rc="200" rm="OK" tn="Thread Group 2-1" dt="text" by="411"/>
<httpSample t="525" lt="525" ts="1306146505234" s="true" lb="HTTP Request" rc="200" rm="OK" tn="Thread Group 2-2" dt="text" by="411"/>


<httpSample t="586" lt="586" ts="1306146611316" s="true" lb="HTTP Request" rc="200" rm="OK" tn="Thread Group 2-1" dt="text" by="411"/>
<httpSample t="523" lt="523" ts="1306146612307" s="true" lb="HTTP Request" rc="200" rm="OK" tn="Thread Group 2-2" dt="text" by="411"/>
<httpSample t="507" lt="507" ts="1306146613306" s="true" lb="HTTP Request" rc="200" rm="OK" tn="Thread Group 2-3" dt="text" by="411"/>

<httpSample t="535" lt="535" ts="1306146615306" s="true" lb="HTTP Request" rc="200" rm="OK" tn="Thread Group 2-5" dt="text" by="411"/>
<httpSample t="526" lt="526" ts="1306146506234" s="true" lb="HTTP Request" rc="200" rm="OK" tn="Thread Group 2-3" dt="text" by="411"/>
<httpSample t="499" lt="498" ts="1306146507234" s="true" lb="HTTP Request" rc="200" rm="OK" tn="Thread Group 2-4" dt="text" by="411"/>
<httpSample t="505" lt="505" ts="1306146508234" s="true" lb="HTTP Request" rc="200" rm="OK" tn="Thread Group 2-5" dt="text" by="411"/>
<httpSample t="536" lt="536" ts="1306146509249" s="true" lb="HTTP Request" rc="200" rm="OK" tn="Thread Group 2-6" dt="text" by="411"/>
</testResults>

In perl,
i need output for the above in the following form,

lt = 704
lt = 525

lt max value = 704
lt min value = 525
lt average value =

lt = 586
lt = 523
lt = 507

lt max value = 586
lt min value = 507
lt average value =

lt = 535
lt = 526
lt = 498
lt = 505
lt = 536

lt max value = 536
lt min value = 498
lt average value =

kindly help..


miller
User

May 24, 2011, 9:27 AM

Post #2 of 2 (344 views)
Re: [techtween] group and print data seperately [In reply to] Can't Post

As already stated on perlmonks:

Use XML::Twig to process the xml, and List::Util to assist you in finding the min/max/sum/average.


Code
use List::Util; 
use XML::Twig;

use strict;
use warnings;

my $xml = do {local $/; <DATA>};

my $twig = XML::Twig->new;
$twig->parse($xml);

my @lts = map {$_->att("lt")} $twig->findnodes(q{//httpSample[@lt]});

print join(',', @lts), "\n";

print min(@lts), "\n";
print max(@lts), "\n";
print sum(@lts), "\n";
# ... pretty easy from ehre

__DATA__
<?xml version="1.0" encoding="UTF-8"?>
<testResults version="1.2">
<httpSample t="704" lt="704" ts="1306146504248" s="true" lb="HTTP Request" rc="200" rm="OK" tn="Thread Group 2-1" dt="text" by="411"/>
<httpSample t="525" lt="525" ts="1306146505234" s="true" lb="HTTP Request" rc="200" rm="OK" tn="Thread Group 2-2" dt="text" by="411"/>
<httpSample t="586" lt="586" ts="1306146611316" s="true" lb="HTTP Request" rc="200" rm="OK" tn="Thread Group 2-1" dt="text" by="411"/>
<httpSample t="523" lt="523" ts="1306146612307" s="true" lb="HTTP Request" rc="200" rm="OK" tn="Thread Group 2-2" dt="text" by="411"/>
<httpSample t="507" lt="507" ts="1306146613306" s="true" lb="HTTP Request" rc="200" rm="OK" tn="Thread Group 2-3" dt="text" by="411"/>
<httpSample t="535" lt="535" ts="1306146615306" s="true" lb="HTTP Request" rc="200" rm="OK" tn="Thread Group 2-5" dt="text" by="411"/>
<httpSample t="526" lt="526" ts="1306146506234" s="true" lb="HTTP Request" rc="200" rm="OK" tn="Thread Group 2-3" dt="text" by="411"/>
<httpSample t="499" lt="498" ts="1306146507234" s="true" lb="HTTP Request" rc="200" rm="OK" tn="Thread Group 2-4" dt="text" by="411"/>
<httpSample t="505" lt="505" ts="1306146508234" s="true" lb="HTTP Request" rc="200" rm="OK" tn="Thread Group 2-5" dt="text" by="411"/>
<httpSample t="536" lt="536" ts="1306146509249" s="true" lb="HTTP Request" rc="200" rm="OK" tn="Thread Group 2-6" dt="text" by="411"/>
</testResults>



(This post was edited by miller on May 24, 2011, 9:31 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives