[Omaha.pm] lines2perl: partition.pl
Jay Hannah
jay at jays.net
Sun Apr 30 12:52:56 PDT 2006
Paul's response.
j
-------- Original Message --------
Subject: Re: lines2perl: partition.pl
Date: Sun, 30 Apr 2006 19:46:25 +0200
From: Paul Johnson <paul at pjcj.net>
To: Jay Hannah <jay at jays.net>
On Sun, Apr 30, 2006 at 10:17:00AM -0500, Jay Hannah wrote:
> LOL!! 20.6 hours later it blew up. :)
Argh - sorry about that. Yes, there are a few LifeLines functions which
I haven't implemented - including all the functions since LifeLines got
its new lease of life.
> I guess I should have tried a MUCH smaller GEDCOM first.
Hmmm. I suppose so.
> Paul: The speed's not really usable, so I'm not going to try to submit a
> gengedcom() Perl conversion to you. Any thoughts on the speed front?
Hey - that's a lame excuse ;-)
As far as speed is concerned, LifeLines is a far less capable language
than Perl, even with the new functions. Combine that with a fairly
mechanical translation into Perl, and you have the potential for a
(un)reasonable slowdown.
The good news is that using Gedcom.pm doesn't have to be slow. For
example, here is code that implements option 1 of partition.ll, that is
it will print out details of all people in each partition of the
database. It uses the same algorithm as partition.ll - in fact I
created it but cutting down the lines2perl translation. It runs quite
fast ;-)
> Perhaps I'll install LifeLines and see if the original script works OK or
> not.
Looks like it did in this case, but the relation script didn't. Did you
try the relation script natively?
#!/usr/bin/perl
use strict;
use warnings;
use Gedcom;
use Getopt::Long;
my $file;
die "usage: $0 -gedcom_file file.ged\n"
unless GetOptions("gedcom_file=s" => \$file) && $file;
my $ged = Gedcom->new(gedcom_file => $file);
my ($partition, $count, %seen);
for my $i ($ged->individuals)
{
next if $seen{$i};
$partition++;
my @q = [ $i, 0 ];
while (@q)
{
my ($i, $hops) = @{shift @q};
next if $seen{$i}++;
push @q, [ $_, $hops + 1 ]
for ($i->parents, $i->spouse, $i->siblings, $i->children);
no warnings "uninitialized";
printf "%5d %3d %3d %7s %32s %15s %15s\n",
++$count, $partition, $hops, $i->xref, $i->name,
$i->get_value("birth date"),
$i->get_value("death date");
}
}
--
Paul Johnson - paul at pjcj.net
http://www.pjcj.net
More information about the Omaha-pm
mailing list