techtween has asked for the wisdom of the Perl Monks concerning the following question:

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 Requ +est" rc="200" rm="OK" tn="Thread Group 2-1" dt="text" by="411"/> <httpSample t="525" lt="525" ts="1306146505234" s="true" lb="HTTP Requ +est" rc="200" rm="OK" tn="Thread Group 2-2" dt="text" by="411"/> <httpSample t="586" lt="586" ts="1306146611316" s="true" lb="HTTP Requ +est" rc="200" rm="OK" tn="Thread Group 2-1" dt="text" by="411"/> <httpSample t="523" lt="523" ts="1306146612307" s="true" lb="HTTP Requ +est" rc="200" rm="OK" tn="Thread Group 2-2" dt="text" by="411"/> <httpSample t="507" lt="507" ts="1306146613306" s="true" lb="HTTP Requ +est" rc="200" rm="OK" tn="Thread Group 2-3" dt="text" by="411"/> <httpSample t="535" lt="535" ts="1306146615306" s="true" lb="HTTP Requ +est" rc="200" rm="OK" tn="Thread Group 2-5" dt="text" by="411"/> <httpSample t="526" lt="526" ts="1306146506234" s="true" lb="HTTP Requ +est" rc="200" rm="OK" tn="Thread Group 2-3" dt="text" by="411"/> <httpSample t="499" lt="498" ts="1306146507234" s="true" lb="HTTP Requ +est" rc="200" rm="OK" tn="Thread Group 2-4" dt="text" by="411"/> <httpSample t="505" lt="505" ts="1306146508234" s="true" lb="HTTP Requ +est" rc="200" rm="OK" tn="Thread Group 2-5" dt="text" by="411"/> <httpSample t="536" lt="536" ts="1306146509249" s="true" lb="HTTP Requ +est" 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..

Replies are listed 'Best First'.
Re: group and print data seperately
by Corion (Patriarch) on May 24, 2011 at 15:37 UTC

    See find min, max and average.

    Also, maybe you want to tell us what problems you have now since you told us in Re^2: find min, max and average that you had solved your problem?

    Please note that this is not a script writing service. We expect you to do most of the work. We will help you learn by answering your concrete questions and providing hints on what to study. But writing your programs is something that you must do yourself.

Re: group and print data seperately
by toolic (Bishop) on May 24, 2011 at 15:37 UTC
Re: group and print data seperately
by wind (Priest) on May 24, 2011 at 15:47 UTC

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

    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 Requ +est" rc="200" rm="OK" tn="Thread Group 2-1" dt="text" by="411"/> <httpSample t="525" lt="525" ts="1306146505234" s="true" lb="HTTP Requ +est" rc="200" rm="OK" tn="Thread Group 2-2" dt="text" by="411"/> <httpSample t="586" lt="586" ts="1306146611316" s="true" lb="HTTP Requ +est" rc="200" rm="OK" tn="Thread Group 2-1" dt="text" by="411"/> <httpSample t="523" lt="523" ts="1306146612307" s="true" lb="HTTP Requ +est" rc="200" rm="OK" tn="Thread Group 2-2" dt="text" by="411"/> <httpSample t="507" lt="507" ts="1306146613306" s="true" lb="HTTP Requ +est" rc="200" rm="OK" tn="Thread Group 2-3" dt="text" by="411"/> <httpSample t="535" lt="535" ts="1306146615306" s="true" lb="HTTP Requ +est" rc="200" rm="OK" tn="Thread Group 2-5" dt="text" by="411"/> <httpSample t="526" lt="526" ts="1306146506234" s="true" lb="HTTP Requ +est" rc="200" rm="OK" tn="Thread Group 2-3" dt="text" by="411"/> <httpSample t="499" lt="498" ts="1306146507234" s="true" lb="HTTP Requ +est" rc="200" rm="OK" tn="Thread Group 2-4" dt="text" by="411"/> <httpSample t="505" lt="505" ts="1306146508234" s="true" lb="HTTP Requ +est" rc="200" rm="OK" tn="Thread Group 2-5" dt="text" by="411"/> <httpSample t="536" lt="536" ts="1306146509249" s="true" lb="HTTP Requ +est" rc="200" rm="OK" tn="Thread Group 2-6" dt="text" by="411"/> </testResults>