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

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Re^2: To find the no of occurenaces and max min value

Replies are listed 'Best First'.
Re^3: To find the no of occurenaces and max min value
by vinoth.ree (Monsignor) on Jul 14, 2014 at 10:54 UTC

    Hay Madhavanll,

    You should not use $2 has key in %hash, please find the modified code.

    Please use code tag to post you code.
    use strict; use warnings; use Data::Dumper; my $file = './data.txt'; 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{$1}->{total} +=$2; if(defined $hash{$1}->{min}) { if ($hash{$1}->{min} > $2) { $hash{$1}->{min} = $2; } } else { $hash{$1}->{min} = $2; } if(defined $hash{$1}->{max}) { if ($hash{$1}->{max} < $2) { $hash{$1}->{max} = $2; } } else { $hash{$1}->{max} = $2; } } else { print "not matching\n"; } } print Dumper \%hash;

    All is well
      Thank you so much.. It works. but im having issue with output in CSV.. if the column(SQLs) contains any comma (,) or question mark (?) then its split-ed with many columns. Tried Encoding => 'base64' in the attachments. but still im facing the same issue. please suggest.

        Have a search for Text::CSV. That will handle correct quoting of the exported values.

        Cheers,
        R.

        Pereant, qui ante nos nostra dixerunt!