in reply to find min, max and average

You should loop over all lt values and find the mininimum and maximum values, or you can cheat and use List::Util to give you minimum and maximum from a list

However, this looks wrong:

my @values = $e->{lt};
You'll get just one value. Try this for starters:
my @values; foreach my $e (@{$data->{httpSample}}) { push @values, $e->{lt}; print "Lt_Value: ", $e->{lt}, "\n"; }
Now you have an array of all values in @values. The rest is now a piece of cake (you'll have to install Scalar-List-Utils if you don't have it already):
use List::Util qw(min max sum); print "Min Lt_Value: ", min(@values), "\n"; print "Max Lt_Value: ", max(@values), "\n"; if(@values) { print "Average Lt_Value: ", (sum(@values)/@values), "\n"; } else { print "No values so no average.\n"; }
n.b. List::Util doesn't have an average() or avg() function, so I have to emulate one using sum() and dividing by the number of elements.

Replies are listed 'Best First'.
Re^2: find min, max and average
by techtween (Novice) on May 24, 2011 at 12:08 UTC
    Thank you monk.. got it right now.

      The issue that i need to get fixed with is that there will be five lines of tags(httpSample tags) then a empty line then another five lines of tag(httpSample tags) then an empty line and so on it goes in this format. Now i need to calculate the minimum and maximum of these each set of five lines(lt value of httpSample tags) seperately and display it.( for the same code listed above, in this thread). Since there is an empty line in between each set of five tags i couldnt figure out how to retrieve each set of five tags into an array and display the same.

        Check the output of XML::Simple (dump it with Data::Dumper), and see if there's a way to distinguish between the groups. If not, you'll have to upgrade from XML::Simple to a more complicated XML module.

        (Did you really say "an empty line"? Empty lines are meaningless in XML. You should nest the related tags in a grouping tag.)