develooper Front page | perl.perl4lib | Postings from April 2018

Re: Converting XML to MARC without reading a file?

Thread Previous | Thread Next
From:
Bruce Van Allen
Date:
April 19, 2018 02:20
Subject:
Re: Converting XML to MARC without reading a file?
Message ID:
r473Ps-10126i-EFFAE10591734415A3D158EE6E68776A@River.local
On 4/18/18 at 5:25 PM, akohler726@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 $string  = "line 1\nline 2\nline 3\n";

open my $fh, "<", \$string;

while (<$fh>) {
     print "Printing $_";
}

close $fh;

# Printing line 1
# Printing line 2
# Printing line 3

$fh is a filehandle like any other. Can you use that?

HTH
-- 

   - Bruce

_bruce__van_allen__santa_cruz__ca_

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About