<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl -w
use strict;

#Sample from biographies.list

#-------------------------------------------------------------------------------
#NM: Bauer, Hank (II)
#
#RN: Henry Albert Bauer
#
#DB: 31 July 1922, East St. Louis, Illinois, USA

print "Working: ";
my $master={};
my $nm=undef;
my $marking=undef;
my $linenumber=1;
my $dotcount=100000;
open (BIOS,"biographies.list") || die "Can't find the biographies list!";
while (&lt;BIOS&gt;) {
    chomp $_;
    if (($linenumber/$dotcount)==int($linenumber/$dotcount)) {print ".";}
    $linenumber++;
    if ($_=~/^(NM|RN|DB): /){
        $marking=$1;
        my @data=split(/..: /,$_);
        if ($marking eq "NM") {
            $nm=$data[1];
            $master-&gt;{$nm}-&gt;{"count"}++;    
        }
        if ($marking eq "RN") {$master-&gt;{$nm}-&gt;{"rn"}=$data[1];}
        if ($marking eq "DB") {$master-&gt;{$nm}-&gt;{"db"}=$data[1];}
    }
}
foreach my $namekey (keys(%$master)) {
    my $purenamekey=$namekey;
    $purenamekey=~s/'//;
    $purenamekey=~s/"//;
    $purenamekey=~s/\(.*\)//;
    $purenamekey=~s/^\s*//;
    $purenamekey=~s/\s*$//;
    $master-&gt;{$namekey}-&gt;{"purekey"}=$purenamekey;
    my @nameparts1=split(",",$purenamekey);
    foreach (@nameparts1) {
        $_=~s/^\s*//;
        $_=~s/\s*$//;
    }
    if (scalar(@nameparts1) &lt;=1) {
        $master-&gt;{$namekey}-&gt;{"discard"}=1;
    }
    else {$master-&gt;{$namekey}-&gt;{"discard"}=0;}
    my @nameparts2=split(" ",$nameparts1[0]);
    my $puresurname=pop(@nameparts2);
    if (exists $master-&gt;{$namekey}-&gt;{"rn"}) {
        my $rn=$master-&gt;{$namekey}-&gt;{"rn"};
        #Remove Brackets (with contents) and quotes
        $rn=~s/\(.*\)//g;
        $rn=~s/'//g;
        $rn=~s/"//g;
        #remove 'the' to end
        $rn=~s/(^| )the( |$).*//i;
        #remove all dots
        $rn=~s/\.//gi;
        #Remove Roman Numerials and Jr. Sr.
        $rn=~s/(^| )(I|II|III|IV|V|VI|VII|VIII|IX|X|XI|XII|XIII)( |$)//i;
        $rn=~s/(^| )(Jr|Sr)( |$)//i;
        #remove initials?
        $rn=~s/(^| )\w( |$)//gi;
        #If there is a comma take the last word on the left of it
        if ($rn=~/,/) {
            my @realnameparts1=split(",",$rn);
            my @realnameparts2=split(" ",$realnameparts1[0]);
            my $realsurname=pop(@realnameparts2);
            if (defined ($realsurname)) {
                $realsurname=~s/^\s*//;
                $realsurname=~s/\s*$//;
                $master-&gt;{$namekey}-&gt;{"realsurname"}=$realsurname;
            }
            else {
                $master-&gt;{$namekey}-&gt;{"realsurname"}=$rn;
            }
        }
        else {
            my @realnameparts=split(" ",$rn);
            my $realsurname=pop(@realnameparts);
            if (defined ($realsurname)) {
                $realsurname=~s/^\s*//;
                $realsurname=~s/\s*$//;
                $master-&gt;{$namekey}-&gt;{"realsurname"}=$realsurname;
            }
            else {
                $master-&gt;{$namekey}-&gt;{"realsurname"}=$puresurname;
            }
        }
        $master-&gt;{$namekey}-&gt;{"realsurname"}=~s/\s*$//;
        $master-&gt;{$namekey}-&gt;{"realsurname"}=~s/^\s*//;
    }
    else {
        $master-&gt;{$namekey}-&gt;{"realsurname"}=$puresurname;
    }
    if (exists $master-&gt;{$namekey}-&gt;{"db"}) {
        my @dateparts=split(",",$master-&gt;{$namekey}-&gt;{"db"});
        my $birthcountry=pop(@dateparts);
        if (defined $birthcountry) {
            if ($birthcountry=~/\d/) {
                $birthcountry=undef; #There was only a date
            }
            else {
                $birthcountry=~s/^\s*//;
                $birthcountry=~s/\s*$//;
                $master-&gt;{$namekey}-&gt;{"birthcountry"}=$birthcountry;
            }
        }
        else {
            $birthcountry=undef;
        }
    }
}

print "\nWait for it: ... (just another minute)";
foreach my $namekey (keys(%$master)) {
    #Do some last minute fixing to the realsurname
    $master-&gt;{$namekey}-&gt;{"realsurname"}=~s/\.//g;
    $master-&gt;{$namekey}-&gt;{"realsurname"}=~s/(^| )\w( |$)//ig;
    $master-&gt;{$namekey}-&gt;{"realsurname"}=~s/(^| )\d*( |$)//g;
    #Doublecheck that we have a single realname
    my $realname=$master-&gt;{$namekey}-&gt;{"realsurname"};
    if ($realname=~/ /){
        my @nameparts=split(/ /,$realname);
        $master-&gt;{$namekey}-&gt;{"realsurname"}=pop(@nameparts);
        $realname=$master-&gt;{$namekey}-&gt;{"realsurname"};
    }
    #Do some last minute fixing to the birthcountry
    my $bc=$master-&gt;{$namekey}-&gt;{"birthcountry"};
    if (defined $bc) {
        $bc=~s/\[/(/g;
        $bc=~s/\]/)/g;
        if ($bc=~/\((.*)\)/){
            my $update=$1;
            $update=~s/^now //i;
            $bc=$update;
        }
        $bc=~s/\)//g;
        $bc=~s/\(//g;
        $bc=~s/"//g;
        $bc=~s/'//g;
        if ($bc eq "West") {
            $bc="Germany"
        }
        $master-&gt;{$namekey}-&gt;{"birthcountry"}=$bc;
    }
}

#Dump the output
open (OUTPUT,"&gt;IMDB-BiosData.txt") || die "Can't open the outfile";
print OUTPUT "NameKey\tPureNameKey\tDiscard\tRealSurname\tBirthCountry\tRealNameString\tBirthString\n";
foreach my $namekey (keys(%$master)) {
    print OUTPUT $namekey."\t";
    print OUTPUT $master-&gt;{$namekey}-&gt;{"purekey"}."\t";
    print OUTPUT $master-&gt;{$namekey}-&gt;{"discard"}."\t";
    if (!exists $master-&gt;{$namekey}-&gt;{"realsurname"}) {$master-&gt;{$namekey}-&gt;{"realsurname"}="";}
    if (!exists $master-&gt;{$namekey}-&gt;{"birthcountry"}) {$master-&gt;{$namekey}-&gt;{"birthcountry"}="";}
    if (!exists $master-&gt;{$namekey}-&gt;{"rn"}) {$master-&gt;{$namekey}-&gt;{"rn"}="";}
    if (!exists $master-&gt;{$namekey}-&gt;{"db"}) {$master-&gt;{$namekey}-&gt;{"db"}="";}
    print OUTPUT $master-&gt;{$namekey}-&gt;{"realsurname"}."\t";
    print OUTPUT $master-&gt;{$namekey}-&gt;{"birthcountry"}."\t";
    print OUTPUT $master-&gt;{$namekey}-&gt;{"rn"}."\t";
    print OUTPUT $master-&gt;{$namekey}-&gt;{"db"}."\n";
}
close (OUTPUT);
print "\nDone!\n";
</pre></body></html>