{
    "mode": "perldoc",
    "parameter": "HTML::PullParser",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/HTML%3A%3APullParser/json",
    "generated": "2026-06-09T20:17:52Z",
    "synopsis": "use HTML::PullParser;\n$p = HTML::PullParser->new(file => \"index.html\",\nstart => 'event, tagname, @attr',\nend   => 'event, tagname',\nignoreelements => [qw(script style)],\n) || die \"Can't open: $!\";\nwhile (my $token = $p->gettoken) {\n#...do something with $token\n}",
    "sections": {
        "NAME": {
            "content": "HTML::PullParser - Alternative HTML::Parser interface\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use HTML::PullParser;\n\n$p = HTML::PullParser->new(file => \"index.html\",\nstart => 'event, tagname, @attr',\nend   => 'event, tagname',\nignoreelements => [qw(script style)],\n) || die \"Can't open: $!\";\nwhile (my $token = $p->gettoken) {\n#...do something with $token\n}\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The HTML::PullParser is an alternative interface to the HTML::Parser class. It basically turns\nthe HTML::Parser inside out. You associate a file (or any IO::Handle object or string) with the\nparser at construction time and then repeatedly call $parser->gettoken to obtain the tags and\ntext found in the parsed document.\n\nThe following methods are provided:\n\n$p = HTML::PullParser->new( file => $file, %options )\n$p = HTML::PullParser->new( doc => \\$doc, %options )\nA \"HTML::PullParser\" can be made to parse from either a file or a literal document based on\nwhether the \"file\" or \"doc\" option is passed to the parser's constructor.\n\nThe \"file\" passed in can either be a file name or a file handle object. If a file name is\npassed, and it can't be opened for reading, then the constructor will return an undefined\nvalue and $! will tell you why it failed. Otherwise the argument is taken to be some object\nthat the \"HTML::PullParser\" can read() from when it needs more data. The stream will be\nread() until EOF, but not closed.\n\nA \"doc\" can be passed plain or as a reference to a scalar. If a reference is passed then the\nvalue of this scalar should not be changed before all tokens have been extracted.\n\nNext the information to be returned for the different token types must be set up. This is\ndone by simply associating an argspec (as defined in HTML::Parser) with the events you have\nan interest in. For instance, if you want \"start\" tokens to be reported as the string 'S'\nfollowed by the tagname and the attributes you might pass an \"start\"-option like this:\n\n$p = HTML::PullParser->new(\ndoc   => $documenttoparse,\nstart => '\"S\", tagname, @attr',\nend   => '\"E\", tagname',\n);\n\nAt last other \"HTML::Parser\" options, like \"ignoretags\", and \"unbrokentext\", can be passed\nin. Note that you should not use the *event*h options to set up parser handlers. That would\nconfuse the inner logic of \"HTML::PullParser\".\n\n$token = $p->gettoken\nThis method will return the next *token* found in the HTML document, or \"undef\" at the end\nof the document. The token is returned as an array reference. The content of this array\nmatch the argspec set up during \"HTML::PullParser\" construction.\n\n$p->ungettoken( @tokens )\nIf you find out you have read too many tokens you can push them back, so that they are\nreturned again the next time $p->gettoken is called.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "The 'eg/hform' script shows how we might parse the form section of HTML::Documents using\nHTML::PullParser.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "HTML::Parser, HTML::TokeParser\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright 1998-2001 Gisle Aas.\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        }
    },
    "summary": "HTML::PullParser - Alternative HTML::Parser interface",
    "flags": [],
    "examples": [
        "The 'eg/hform' script shows how we might parse the form section of HTML::Documents using",
        "HTML::PullParser."
    ],
    "see_also": []
}