Is there any way I can make my Perl wrapper for yaz-marcdump, below, more
efficient?
I have (yet another) application that takes MARC records as input, parses
them, and indexes them. My indexer(s) want UTF-8 but sometimes my records
are encoded as MARC-8. Consequently, I wrote a subroutine (m2u) that runs
yaz-marcdump with a number of command-line options, traps STDOUT, and
returns the results converted from MARC-8 to UTF-8.
#!/usr/bin/perl
# define yaz-marcdump;
use constant YAZ => 'yaz-marcdump -f MARC-8 -t UTF-8 -o marc -l 9=97 ';
# sanity check
if ( ! $ARGV[ 0 ]) {
print "Usage: $0 path/to/marc\n";
exit;
}
# do the work (marc-8 to utf-8) and quit
print &m2u( YAZ, $ARGV[ 0 ] );
exit;
# convert
sub m2u {
$y = shift; # yaz stub
$f = shift; # file to process
$r = ''; # return value
# run yaz and trap the output
open ( C, "$y$f |" ) or die "Can't open converter: $!\n";
while ( <C> ) { $r = $_ }
close C;
# done
return $r;
}
For extra credit, is there anyway I can optimize m2u? For example, is there
anyway to get rid of the while loop and slurp up yaz-marcdump's output in
one go?
--
Eric Lease Morgan
|