How do I use SGMLS.pm?

Links: Next Previous Up Top

# How do I use `SGMLS.pm`?

First, you need to copy the file `SGMLS.pm` to a directory where perl can find it (on a Unix system, it might be `/usr/lib/perl5` or `/usr/local/lib/perl5`, or whatever the environment variable `PERL5LIB` is set to) and make certain that it is world-readable.

Next, near the top of your `perl5` program, type the following line:

    use SGMLS;

You must then open up a file handle from which `SGMLS.pm` can read the data from an `sgmls` or `nsgmls` process, unless you are reading from a standard handle like `STDIN` -- for example, if you are piping the output from `sgmls` to a `perl5` script, using something like

    sgmls foo.sgml | perl myscript.pl

then the predefined filehandle `STDIN` will be sufficient. In DOS, you might want to dump the sgmls output to a file and use it as standard input (or open it explicitly in perl), and in Unix, you might actually want to open a pipe or socket for the input. `SGMLS.pm` doesn't need to seek, so any input stream should work.

To parse the `sgmls` or `nsgmls` output from the handle, create a new object instance of the `SGMLS` class with the handle as an argument, i.e.

    $parse = new SGMLS(STDIN);

(You may create more than one `SGMLS` object at once, but each object must have a unique handle pointing to a unique stream, or chaos will result.) Now, you can retrieve and process events using the `next_event` method:

    while ($event = $parse->next_event) {
        #do something with each event
    }

Links: Next Previous Up Top