--- /dev/null
+#!/usr/bin/perl -w
+
+# Polaris exports patrons in MARC format. This script turns the data into a TSV that can be imported with \copy.
+
+use strict;
+use MARC::Record;
+use MARC::File::USMARC;
+use Equinox::Migration::SubfieldMapper 1.004;
+
+my $file = MARC::File::USMARC->in("PATRONS.mrc");
+my $serial = 0;
+my @modlist = qw( multi ignoremulti bib required ); # Not sure what these do, but I'll cargo-cult it for now
+my $mapfile = 'patron.map';
+
+# initialize map and taglist
+my $sfmap = Equinox::Migration::SubfieldMapper->new( file => $mapfile, mods => \@modlist );
+
+my $temp = $sfmap->tags(); # $temp is an arrayref
+my @fields = sort @$temp;
+
+while ( my $marc = $file->next() ) {
+ # Preliminaries
+ print $serial++ . "\t";
+ print $marc->leader() . "\t";
+ print $marc->field('001')->data() . "\t";
+ print $marc->field('005')->data() . "\t";
+ print $marc->field('008')->data() . "\t";
+ # Fields and subfields beyond the preliminaries
+ foreach my $tag (@fields) {
+ my $temp = $sfmap->subfields($tag);
+ foreach my $sf (sort @$temp) {
+ if ($sfmap->has($tag, $sf)) {
+ print $marc->subfield($tag, $sf);
+ }
+ print "\t";
+ }
+ }
+ print "\n";
+}
+
+$file->close();
+undef $file;