#!/usr/bin/perl # This program renumbers Pat's 18thC erotica bib.; input # file was Pat's interleaved and renumbered copy - 16/10/00. # Run again 29/10/00 on new dataset. # # It also adds in a vertical bar (|) to spearate the name # and title fields # # NO sorting of records done # # NB - search for "delete Pat's orig number" to choose # to do so ro not # $/ = "\n\n"; $new_num = 0; $record_count = 0; $last_begin = ""; $begin = ""; open(FILE, ">errors"); while (<>) { # check for name field &checkforname($_); if ($_ =~ /^\[/) { $record_count++; # delete carriage returns $_ =~ s/\n([^\n])/ $1/g; $_ =~ s/\- ([a-zA-Z])/\-$1/g; $_ =~ s/\-\-/\-\-/g; $_ =~ s/ / /g; $_ =~ s// /g; # get Pat's number $_ =~ /^\[(.*?)\]\t/; $pat_num = $1; # replace spaces after number with tab $_ =~ s/(^\[.*?\])[ ]+/$1\t/; # delete old counter $_ =~ s/ +\{[0-9]+\}\n/\n/g; # input name/title separator # if ($_ =~ /(.*\,) /) # { # $_ =~ s/(.*\,) /$1\t\|/g; # } # tidy spacing # $_ =~ s/ +/ /g; # $_ =~ s/\: /\: /g; # replace S with … # $_ =~ s/ S / \&hellip\; /g; # $_ =~ s/ S\, / \&hellip\;\, /g; # renumbering algorithm $lastbegin = $begin; if ($pat_num =~ /[a-z]/) { $pat_num =~ /([0-9\.]+)(.*)/; $begin = $1; $rest = $2; } else { $begin = $pat_num; $rest = ""; } if ($lastbegin ne $begin) { $new_num++; } # delete Pat's orig number $_ =~ s/^\[.*?\](\t.*)/$1/; # and add record counter $outrec = $_; $outrec =~ s/(.*)[ ]+$/$1/g; $outrec =~ s/(.*)/$1\{$record_count\}/; # print new number and record print "\[$new_num$rest\]$outrec"; } elsif ($_ =~ /\*\*\*\*\*\*\* 1/) { # print year separators print; } else { print FILE "$_"; } } sub checkforname { local($rec) = $_[0]; if ($rec !~ m/(.*\,) \|/) { print FILE $_; } }