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 from one), and then used the bytes from
the scalar variable, but I think all my data is ASCII so far.





On Thu, Apr 19, 2018 at 2:54 PM, Andy Kohler <akohler...@gmail.com> wrote:

> 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 without luck earlier.  David kindly sent a complete
> example - which worked in isolation, but failed in the context of my
> program with a frustrating "Couldn't open file handle: Invalid argument"
> until I realized I'd forgotten the essential "use warnings"... which gave
> me the frustrating but much more helpful:
>
> "Strings with code points over 0xFF may not be mapped into in-memory file
> handles"
>
> A moment with Google found pages like this:
> https://bugzilla.redhat.com/show_bug.cgi?id=1048324
>
> which helped me realize that the XML I was retrieving from WorldCat really
> was encoded as UTF-8, which I hadn't accounted for so far.
>
> Wrapping my retrieved XML like so:
>   utf8::encode($contents);
>
> has resolved the problem, so far at least - have to test more with records
> with diacritics to be sure.  But this helps me move forward.
>
> Thanks again! --Andy
>
>
> On Wed, Apr 18, 2018 at 4:25 PM, Andy Kohler <akohler...@gmail.com> wrote:
>
>> 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 in a
>> variable, retrieved via LWP::Simple->get().
>>
>> 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?
>>
>> I've tried things like:
>> $xml = get($api_call); # also verified that $xml now contains MARCXML for
>> 1 or more records
>> my $batch =  MARC::File::XML->in($xml);
>> while (my $record = $batch->next()) {
>>   print $record;
>> }
>> but I get the error: Can't call method "next" on an undefined value
>>
>> Thanks --Andy
>>
>>
>

Reply via email to