in reply to To find the no of occurenaces and max min value

use strict; use warnings; use Data::Dumper; my %hash; while(<DATA>) { chomp(); if(/from (\w+) (.*) Time Taken :: (\d+)/) { print "$1=$3\n"; $hash{$1}->{count}++; $hash{$1}->{total} +=$3; if(defined $hash{$1}->{min}) { if ($hash{$1}->{min} > $3) { $hash{$1}->{min} = $3; } } else { $hash{$1}->{min} = $3; } if(defined $hash{$1}->{max}) { if ($hash{$1}->{max} < $3) { $hash{$1}->{max} = $3; } } else { $hash{$1}->{max} = $3; } } else { print "not matching\n"; } } print Dumper \%hash; __DATA__ SQL :: select * from person ...etc , Time Taken :: 30 SQL :: select * from emp ...etc , Time Taken :: 5 SQL :: select * from home ...etc , Time Taken :: 20 SQL :: select * from emp ...etc , Time Taken :: 30 SQL :: select * from person ...etc , Time Taken :: 10 SQL :: select * from home ...etc , Time Taken :: 20 SQL :: select * from person ...etc , Time Taken :: 50

Sorry for the lengthy code. the hash contains the details u wanted, you can format it as u want.


All is well

Replies are listed 'Best First'.
Re^2: To find the no of occurenaces and max min value
by Madhavan11 (Initiate) on Jul 14, 2014 at 09:18 UTC

    Thanks for ur reply.. I tried with above code.. but still im not able to get the min and max values correctly. only 2 hash variables Please find the code


    my %hash; open my $fh, '<', $file or die "Could not open '$file' $!"; while(<$fh>) { chomp(); if(/SQL:: (.*),Time Taken:: (.*)/i) { #print "$1=$3\n"; $hash{$1}->{count}++; $hash{$2}->{total} +=$2; if(defined $hash{$2}->{min}) { if ($hash{$2}->{min} > $2) { $hash{$2}->{min} = $2; } } else { $hash{$2}->{min} = $2; } if(defined $hash{$2}->{max}) { if ($hash{$2}->{max} < $2) { $hash{$2}->{max} = $2; } } else { $hash{$2}->{max} = $2; } } else { print "not matching\n"; } } print Dumper \%hash;
    Output should be
    ------------
    SQL No of occu Min Max select * from person 3 10 50 select * from emp 2 5 30
A reply falls below the community's threshold of quality. You may see it by logging in.