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, this is only useful for a historic record of work done. You may find a link to the currently used concept or function in this article, if not you can contact the author to find out what has taken the place of this legacy item.
#!/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";