use strict;
use warnings;
my $filename = 'ssdm3'; #time: takes 1:20 to run
open(my $fh, '<:encoding(UTF-8)', $filename)
or die "Could not open file '$filename' $!";
our $i=0;
our $last="start";
our $oldestbirth=2020;
our $newestbirth=0;
our $oldestdeath=2020;
our $newestdeath=0;
our $oldestage=0;
our $youngestage=150;
our $totalage=0;
our $totalbirth=0;
our $totaldeath=0;
while (my $row = <$fh>) {
chomp $row;
my $ssnbase=(substr $row, 1,3).("-").(substr $row, 4,2);
if ($last eq "start"){$last = $ssnbase; }
if ($ssnbase eq $last){$i++;}
else {
my $avgage = int($totalage/$i);
my $avgbirthyr = int($totalbirth/$i);
my $avgdeathyr = int($totaldeath/$i);
# ssnblock, number found,
# 001-01, 6397, 26, 83, 1969, 0000, 1898, 1924, 1925, 1981, 2013
#$SSNBlock,$count, $youngestage,$avgage,$oldestage,$oldestbirth,$avgbirthyr,$newestbirth,$oldestdeath,$avgdeathyr,newestdeath
print $last. ",".$i.",".$youngestage.",".$avgage.",".$oldestage.",".$oldestbirth.",".$avgbirthyr.",".$newestbirth.",".$oldestdeath.",".$avgdeathyr.",".$newestdeath."\n";
$i=1;
$last=$ssnbase;
$oldestbirth=2020;
$newestbirth=0;
$oldestdeath=2020;
$newestdeath=0;
$oldestage=0;
$youngestage=150;
$totalage=0;
$totalbirth=0;
$totaldeath=0;
}
my $death = substr $row, 69,4;
my $birth = substr $row, 77,4;
if ($death < 1899){$death = 1899;} #unknown birth, unknown age, just put at 50
if ($birth < 1850){$birth = $death - 50;} #unknown birth, unknown age, just put at 50
if ($death < $birth){$death = $oldestdeath;$birth = $oldestbirth;}
my $age = $death - $birth;
$totalage+=$age;
$totalbirth+=$birth;
$totaldeath+=$death;
# if ($age > 110){print "age: ". $age. " death:" . $death . " birth: ". $birth. "\n";}
if ($age > $oldestage){$oldestage = $age;}
if ($age < $youngestage){$youngestage = $age;}
if ($birth > $newestbirth){$newestbirth = $birth;}
if ($birth < $oldestbirth){$oldestbirth = $birth;}
if ($death > $newestdeath){$newestdeath = $death;}
if ($death < $oldestdeath){$oldestdeath = $death;}
#print $ssnbase."\n";
#print "$row\n";
#print $i;
#print "\n";
}
info@numchk.com