Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^4: peek at STDIN, to determine data type and then pass STDIN to a parser

by aral (Acolyte)
on Jan 08, 2015 at 10:12 UTC ( [id://1112633]=note: print w/replies, xml ) Need Help??


in reply to Re^3: peek at STDIN, to determine data type and then pass STDIN to a parser
in thread peek at STDIN, to determine data type and then pass STDIN to a parser

Okay - I have gotten your code to work, and to do what I want. Now this may be a beginners question - but:

How on earth do I get XML::Twig's parse function to use the iterator instead of a filehandle?

my $inputHandle = create_iterator(); $t->parse (<$inputHandle>);

exits with error message "Not a GLOB reference at ./script.pl line xy.".

And

$t->parse ($inputHandle);

spits out: "not well-formed (invalid token) at line 1, column 4, byte 4 at /usr/lib/x86_64-linux-gnu/perl5/5.20/XML/Parser.pm line 187. at ./script.pl line xy."

So how do I typecast the iterator in order to treat it like a file handle?

Replies are listed 'Best First'.
Re^5: peek at STDIN, to determine data type and then pass STDIN to a parser
by MidLifeXis (Monsignor) on Jan 09, 2015 at 17:48 UTC

    Ok, I have had a chance to look at this - my statement above about it "treat it as just a file handle" is not quite accurate. It needs a little more support to make it look like an IO::Handle or a tied file handle. I am considering a self-project to be able to export an Iterator::Simple object as an IO::Handle object.

    I have been using the iterators with the ->next() or <$iterator> syntax, so stating that they just behave like a file handle is definitely a mea culpa. Given a couple of days perhaps I can have something available that will wrap an iterator as a globish object. I will update here if/when that happens.

    --MidLifeXis

      If you could find a way to do this that would be much appreciated. I would try it myself, but I am afraid I am still way too clueless about the lower level mechanics of perl :)

      I understand you've probably been too busy to get back to this. However, the idea and approach seemed very valuable, and I would therefore like to bump the topic, in case someone has the time and interest to come up with a solution to wrap the above iterator approach in a glob like object.

      Anyone? :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1112633]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-19 20:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found