<HTML> <HEAD> <TITLE>How do I use SGMLS.pm?</TITLE> </HEAD> <BODY> <P><B>Links</B>: <A HREF=sgmlsevent.html>Next</A> <A HREF=perl5.html>Previous</A> <A HREF=sgmlspm.html>Up</A> <A HREF=sgmlspm.html>Top</A></P> <H1>How do I use <A HREF=sgmlspm.html><TT>SGMLS.pm</TT></A>?</H1> <P>First, you need to copy the file <A HREF=sgmlspm.html><TT>SGMLS.pm</TT></A> to a directory where perl can find it (on a Unix system, it might be <TT>/usr/lib/perl5</TT> or <TT>/usr/local/lib/perl5</TT>, or whatever the environment variable <TT>PERL5LIB</TT> is set to) and make certain that it is world-readable.</P> <P>Next, near the top of your <A HREF="http://www.metronet.com/0/perlinfo/perl5/manual/perl.html"><TT>perl5</TT></A> program, type the following line:</P> <P> <PRE>use SGMLS;</PRE> </P> <P>You must then open up a file handle from which <A HREF=sgmlspm.html><TT>SGMLS.pm</TT></A> can read the data from an <TT>sgmls</TT> or <A HREF="http://www.jclark.com/sp.html"><TT>nsgmls</TT></A> process, unless you are reading from a standard handle like <TT>STDIN</TT> -- for example, if you are piping the output from <TT>sgmls</TT> to a <A HREF="http://www.metronet.com/0/perlinfo/perl5/manual/perl.html"><TT>perl5</TT></A> script, using something like</P> <P> <PRE>sgmls foo.sgml | perl myscript.pl</PRE> </P> <P>then the predefined filehandle <TT>STDIN</TT> 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. <A HREF=sgmlspm.html><TT>SGMLS.pm</TT></A> doesn't need to seek, so any input stream should work.</P> <P>To parse the <TT>sgmls</TT> or <A HREF="http://www.jclark.com/sp.html"><TT>nsgmls</TT></A> output from the handle, create a new object instance of the <TT>SGMLS</TT> class with the handle as an argument, i.e.</P> <P> <PRE>$parse = new SGMLS(STDIN);</PRE> </P> <P>(You may create more than one <TT>SGMLS</TT> object at once, but each object <EM>must</EM> have a unique handle pointing to a unique stream, or <EM>chaos</EM> will result.) Now, you can retrieve and process events using the <TT>next_event</TT> method:</P> <P> <PRE>while ($event = $parse->next_event) { #do something with each event }</PRE> </P> <P><B>Links</B>: <A HREF=sgmlsevent.html>Next</A> <A HREF=perl5.html>Previous</A> <A HREF=sgmlspm.html>Up</A> <A HREF=sgmlspm.html>Top</A></P> <ADDRESS>David Megginson <A HREF="mailto:dmeggins@aix1.uottawa.ca"><dmeggins@aix1.uottawa.ca></A></ADDRESS> </BODY> </HTML>