Thanks a lot for your guidance Sir.Here is the code with latest updates,
#!/usr/bin/env perl
use strict; use warnings;
my %h;
my %m;
my %db;
while(<DATA>){
chomp;
my @fields = split;
my ($date,$database_name,$speed) = @fields[1,2,3];
my ($date_hour,$minute) = split (/:/,$date) ;
my $date_hour_minute = join (':',$date_hour,$minute) ;
$h{$date_hour}{$database_name} += $speed;
$m{$date_hour_minute}{$database_name} += $speed;
$db{$database_name} = 1;
}
print " collectionTime";
for my $db_keys (sort keys %db){
print " $db_keys"; # adjust spaces to line things up
}
print "\n";
for my $h_keys (sort keys %h){
print $h_keys; # print the date/hour
for my $db_keys (sort keys %db){
print " $h{$h_keys}{$db_keys}"; # pad with enough spaces to
+ match header
}
print "\n"; # this goes outside the inner loop, to end the line
}
Number of databases at anytime will be less than 10, do you think still sorting the %db hash keys once and putting them in an array will be useful here?
One more clarification, the total amount of data which needs to be computed will be around 100k records. So do you think this approach will be efficient enough? Please guide me if you think there is room for improving efficiency.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|