Family Origins Export.pl

From Organic Design wiki
Legacy.svg Legacy: This article describes a concept that has been superseded in the course of ongoing development on the Organic Design wiki. Please do not develop this any further or base work on this concept, now this page is for historic record only.
#!/usr/bin/perl -w
use Cwd;

open(FO, '<', cwd.'/family-tree.txt') or die "Can't open 'FO'!";
open(INDEX, '>', cwd.'/exported/index.txt') or die "Can't open 'INDEX'!";
$i = 0;
while (<FO>) {
	if (/^(.*),\s*(.+?)\s+\(([MF ]+)\)/) {
		($surname, $name, $sex) = ($1, $2, $3);
		$surname =~ s/[\"]/\'/g;
		$surname =~ s/[\(\)?\\\/:]//g;
		$name =~ s/[\"]/\'/g;
		$name =~ s/[\(\)?\\\/:]//g;
		print "$surname,$name\n";
		close FILE;
		open (FILE, '>', cwd."/exported/$surname,$name.txt") or die "Couldn't open '$surname,$name.txt'!";
		print FILE "sex:$sex\n";
		print INDEX "$surname,$name\n";
		$i++;
		}
	if (/^\t(.+)\t(.+)$/) { print FILE "$1:$2\n" }
	}
close FO;
close FILE;
close INDEX;

print "\n\n$i entries found.\n";