Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: To find the no of occurenaces and max min value

by vinoth.ree (Monsignor)
on Jul 14, 2014 at 10:54 UTC ( [id://1093527]=note: print w/replies, xml ) Need Help??


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

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

Replies are listed 'Best First'.
Re^4: To find the no of occurenaces and max min value
by Madhavan11 (Initiate) on Jul 14, 2014 at 13:58 UTC
    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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1093527]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-03-28 22:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found