How to interchange a handle and a scalar?

B

Bryan

I am using a perl package (Data::Table) that has a function called
fromTSV and takes a name or a handler to a TSV file.

But I am generating a TSV file in memory from an XML/XSLT transform. I
want to pop this into the Data::Table stuff, but would prefer not to
dump it to disk and then read it back in.

To do this I need to give fromTSV what it expects, right? So I would
need to provide the function with a handler to a string (?).

Or maybe this is just impossible and I should rewrite fromTSV to suit my
needs?

Any hints?

Thanks,
B
 
X

xhoster

Bryan said:
I am using a perl package (Data::Table) that has a function called
fromTSV and takes a name or a handler to a TSV file.

But I am generating a TSV file in memory from an XML/XSLT transform. I
want to pop this into the Data::Table stuff, but would prefer not to
dump it to disk and then read it back in.

To do this I need to give fromTSV what it expects, right? So I would
need to provide the function with a handler to a string (?).

Yes. You can do that like so:

my $handler = new IO::Scalar \$string;

See perldoc IO::Scalar

On new enough Perls, you can do the same thing with open:

open($handler, '<', \$string) or die $!;

Xho
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top