link to Home Page

icon Perl Program


The source code of the program:

#!/usr/bin/perl -w

use strict;

my %counts;
my $state = 0;

while (<>) {
if (/^(\d\d\d\d)\//) {
$state = 1;
}
next if $state == 0;
my @eqdata = split " ", $_;

my ($year) = $eqdata[0] =~ /(\d\d\d\d)/ or $state = 0, next;
my $magn = $eqdata[5];
my $exponentiated = 10 ** $magn;

$counts{$year}{'cnt'}++;
$counts{$year}{'exp'} += $exponentiated;
$counts{$year}{'pwr'} += $exponentiated ** 2;
}

foreach (sort keys %counts) {
my $c = $counts{$_}{'cnt'};
printf "%4d: %2d q.; pwr. %8.0fG, exp. %8.0fk, magn. %3.2f\n",
$_,
$c,
$counts{$_}{'pwr'} / 1000000000 / $c,
$counts{$_}{'exp'} / 1000 / $c,
log($counts{$_}{'exp'} / $c) / log(10);
}

Offered by Antti.

icon