[open-ils-commits] r342 - conifer/trunk/tools/migration-scripts (dbs)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Apr 16 23:39:17 EDT 2009


Author: dbs
Date: 2009-04-16 23:39:15 -0400 (Thu, 16 Apr 2009)
New Revision: 342

Added:
   conifer/trunk/tools/migration-scripts/fix_bad_marcxml.pl
Log:
Another preprocessing script takes shape...


Added: conifer/trunk/tools/migration-scripts/fix_bad_marcxml.pl
===================================================================
--- conifer/trunk/tools/migration-scripts/fix_bad_marcxml.pl	                        (rev 0)
+++ conifer/trunk/tools/migration-scripts/fix_bad_marcxml.pl	2009-04-17 03:39:15 UTC (rev 342)
@@ -0,0 +1,33 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+foreach my $file (@ARGV) {
+	clean_empty_datafields($file);
+}
+
+sub clean_empty_datafields {
+	my $file = shift;
+
+	# Empty datafields anger MARC::File::XML
+	open(FH, '<', $file) or die $!;
+	open(CLEAN, '>', "$file.new");
+
+	my ($trim, $lastline) = (0, '');
+	while (<FH>) {
+		if ($_ =~ m#</datafield># and $lastline =~ m#<datafield#) {
+			$trim = 1;
+		} elsif ($trim) {
+			$trim = 0;
+		} else {
+			print CLEAN $lastline;
+			$trim = 0;
+		}
+		
+		$lastline = $_;
+	}
+	print CLEAN $lastline;
+
+	close(FH);
+	close(CLEAN);
+}



More information about the open-ils-commits mailing list