#!/usr/local/bin/perl use warnings; use strict; use vars qw(%opts $author_rx $pubtype_rx %pubmap %titlemap); use Getopt::Std; sub usage { my $err = shift || ''; print $err, ; exit; } $opts{t} = '.*'; # default getopts('ha:d:t:', \%opts) or usage "Invalid Args.\n"; usage() if $opts{h}; usage "Missing Mandatory Args.\n" unless defined $opts{d} and defined $opts{a}; $author_rx = qr/\Q$opts{a}/; $pubtype_rx = qr/$opts{t}/; open TITLES, "$opts{d}/titles.dbase" or die "couldn't open titles.dbase file"; open PUBS, "$opts{d}/pubs.dbase" or die "couldn't open pubs.dbase file"; while () { my $line = $_; chomp $line; # split ignores trailing empty fields unless you ask for # a specific number of fields (ignore trailing |) ... my @fields = split /\|/, $line, ($line =~ tr/|/|/); next unless $fields[1] =~ /$author_rx/; foreach my $pubcode (split /\,/, $fields[5]) { $pubmap{$pubcode} = [] unless exists $pubmap{$pubcode}; push @{$pubmap{$pubcode}}, $line; } } while () { my $line = $_; chomp $line; # split ignores trailing empty fields unless you ask for # a specific number of fields (ignore trailing |) ... my @fields = split /\|/, $line, ($line =~ tr/|/|/); next unless exists $pubmap{$fields[0]}; next unless $fields[8] =~ /$pubtype_rx/; foreach my $titleline (@{$pubmap{$fields[0]}}) { my $title = (split /\|/, $titleline)[0]; $titlemap{$title} = [] unless exists $titlemap{$title}; push @{$titlemap{$title}}, "$title|$line$titleline\n"; } } foreach my $title (sort keys %titlemap) { foreach my $line (@{$titlemap{$title}}) { print $line; } } __END__ Usage: isfdb-list-author.pl -d dbase_compiled_dir -a auth_substr [-t pubtype_regex ] Examples: isfdb-list-author.pl -d ~/isfdb/dbase.compiled -a Asimov isfdb-list-author.pl -d ~/isfdb/dbase.compiled -a 'G. Harry Stine^Lee Correy' isfdb-list-author.pl -d ~/isfdb/dbase.compiled -a Asimov -t 'hc|pb' isfdb-list-author.pl -d ~/isfdb/dbase.compiled -a Asimov -t '^$' Output: One record per title/pub combo that mathches the specified criteria. The 1st field is the title, after that comes all of the fields about the publication, and then all of the fields about the title. In standard ISFDB compiled DB format there is a trailing | after the last field.