4 use Time::HiRes qw/time/;
12 my ($userid,$sourceid,$rec_id,$entry_file,$map_file,$id_tag) = (1,2,1,'record_entry.sql','record_id_map.pl','//*[@tag="035"][1]');
15 "sourceid" => \$sourceid,
16 "sql_output=s" => \$entry_file,
17 "tcn_output=s" => \$map_file,
18 "userid=i" => \$userid,
19 "first=i" => \$rec_id,
20 "id_tag_xpath=s" => \$id_tag,
25 open RE, ">$entry_file" or die "Can't open $entry_file! $!\n";
28 SET CLIENT_ENCODING TO 'UNICODE';
29 COPY biblio.record_entry (id,editor,creator,source,tcn_value,marc,last_xact_id) FROM STDIN;
34 my $parser = XML::LibXML->new;
37 while ( $xml .= <STDIN> ) {
44 my $doc = $parser->parse_string($xml);;
45 my @nodes = $doc->documentElement->findnodes( $id_tag );
47 $tcn .= $n->textContent;
49 $tcn =~ s/^\s*(\.+)\s*/$1/o;
62 $tcn =~ s/^.*?(\w+)\s*$/$1/go;
65 warn "\nNo TCN found for rec # $rec_id\n";
71 if (exists($$tcn_map{$tcn})) {
72 warn "\n !! TCN $tcn already exists!\n";
78 $$tcn_map{$tcn} = $rec_id;
80 print RE join("\t", ($rec_id,$userid,$userid,$sourceid,$tcn,$xml,$xact_id))."\n";
87 print RE "SELECT setval('biblio.record_entry_id_seq'::TEXT, $rec_id);\n";
89 open MAP, ">$map_file" or die "Can't open $map_file! $!\n";
90 print MAP Data::Dumper->Dump([$tcn_map],['tcn_map']);