Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^3: Parsing HTML/XML with Regular Expressions (XML::Twig)

by Discipulus (Monsignor)
on Oct 17, 2017 at 19:45 UTC ( #1201529=note: print w/replies, xml ) Need Help??

in reply to Re^2: Parsing HTML/XML with Regular Expressions (XML::Twig)
in thread Parsing HTML/XML with Regular Expressions

You presumed ~right about DATA filehandle.

The and docs specify parse    $string or \*OPEN_FILEHANDLE among twig's methods.

So you are right: I had to pass an handle not an iterator (?) like <DATA>

I dunno when I took this bad habit but if you look at this and this other one and this other too and probably many others of mines, $twig->parse(<DATA>) works!!

So $twig->parse(<DATA>) does not works with your example but i can confirm that passing the filehandle $twig->parse(\*DATA) or even $twig->parse(*DATA) works as expected.

Can be that wrong form works (at least sometimes) because of the XML::Twig ability to parse streams of XML?


There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^4: Parsing HTML/XML with Regular Expressions (XML::Twig)
by haukex (Abbot) on Oct 18, 2017 at 19:21 UTC

    In those three examples you linked to, right before you say <DATA> you do $/='';, which enables "paragraph mode", it's as if the input record separator $/ was /\n\n+/.

    So you are right: I had to pass an handle not an iterator (?) like <DATA>

    <DATA> is the equivalent of readline(DATA), and since readline is being called in list context, it'll read all the records from the handle and return a list of them. So as long as your __DATA__ section doesn't contain any empty lines, it's essentially the same as a slurp - this is probably why the "wrong form" still works.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1201529]
[usemodperl]: what the hell happened to the monastery?
usemodperl gets scolded by little old ladies on every dang post
[usemodperl]: did we get invaded by soy boys or what? it wasn't like this 20 years ago :-)
[usemodperl]: i can see the old tgimers hiding out on reddit! lol
[usemodperl]: no wonder this place is so... popular
[marto]: your account is 7 days old, how old are these 'old tgimers'?
[choroba]: usemodpoerl Do you have a question? Do you want to help someone? Or do you just want to troll?
[usemodperl]: perlmonks used to be a safe space for perl coders, now it's like having an annoying girlfriend...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2018-06-24 15:43 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.