#!/usr/bin/perl # authority2list.pl - output a tab-delimited file of authority data # Eric Lease Morgan # March 24, 2016 - first cut # March 29, 2016 - added command-line input and additional (empty) field as output # require use MARC::Batch; use strict; # sanity check my $file = $ARGV[ 0 ]; if ( ! $file ) { print "Usage: $0 \n"; exit; } # initialize my $batch = MARC::Batch->new( 'USMARC', $file ); binmode STDOUT, ':utf8'; # output a header print "id\tbrief name\tdate\tfull name\ttries\ttotal\tauthorized name\tURI\tLCCN\n"; # process each record while ( my $record = $batch->next ) { # local id my $id = $record->field( '001')->as_string; # process each name field foreach my $field ( $record->field( '1..' ) ) { # skip previously authorized headings next if ( $field->subfield( '0' ) ); # parase my $name = $field->as_string; my $_a = $field->subfield( 'a' ); my $_d = ''; if ( $field->subfield( 'd' ) ) { $_d = $field->subfield( 'd' ) } # output print "$id\t$_a\t$_d\t$name\t\t\t\t\t\n"; } } # done exit;