Re: Converting XML to MARC without reading a file?

2018-04-18 Thread David Cook
I'm glad that I was able to help! I had wondered if you were going to run into encoding issues, and I had thought about warning you... but I figured that was a different piece of the puzzle. So far, I've actually only written to in-memory file handles (my example above was the first time reading f

Re: Converting XML to MARC without reading a file?

2018-04-18 Thread Andy Kohler
Many thanks to David, Bruce and Karl for suggestions - all were helpful! David and Bruce both reminded me that scalar variables can be treated as file handles: open(my $fh, "<", \$xml) or die "Couldn't open file handle: $!"; my $batch = MARC::Batch->new( 'XML', $fh ); I had tried this wit

Re: Converting XML to MARC without reading a file?

2018-04-18 Thread Bruce Van Allen
On 4/18/18 at 5:25 PM, akohler...@gmail.com (Andy Kohler) wrote: Do I have to write the XML to a file, then read it in again to convert it? Or am I just missing something obvious? Perl lets you open a reference to a scalar variable as a file. #!/usr/bin/perl use strict; use warnings; my $st

Re: Converting XML to MARC without reading a file?

2018-04-18 Thread David Cook
I've just tested my theory, and it worked great. Here's some code that you can try at home: #!/usr/bin/perl use strict; use warnings; use MARC::File::XML; use MARC::Batch; my $xml; while (my $line = ){ $xml .= $line; } open(my $fh, "<", \$xml) or die "Couldn't open file handle: $!"; my $batc

Re: Converting XML to MARC without reading a file?

2018-04-18 Thread David Cook
Hey Andy, That does sound like an annoying problem. Someone else might have a better answer, but I think I have a clever solution... Instead of using MARC::File::XML directly, you can use MARC::Batch instead: my $batch = MARC::Batch->new( 'XML', $filename ); According to the MARC::Batch documen

Converting XML to MARC without reading a file?

2018-04-18 Thread Andy Kohler
Hi - I'm pulling records from the WorldCat Search API in MARCXML, and need to convert them to binary MARC for further evaluation, which I'll do via MARC::Record. Problem: Converting from MARCXML via MARC::File::XML seems to require reading the records from a file. I've already got the XML stored