Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Using Perl for plugins...

by dockthepod (Acolyte)
on Mar 08, 2002 at 00:48 UTC ( [id://150192]=perlquestion: print w/replies, xml ) Need Help??

dockthepod has asked for the wisdom of the Perl Monks concerning the following question:

Hello all,

I'm writing a program for Mac OS X in objective-c and whatnot but I thought that it would be really cool if I could use perl to format the output. Basically the program works with XML data and I would like Perl bit to be able to take the XML file and do some formatting stuff. For example, a plugin could take some XML data that has a date and appointment info and make a nice html calendar. I know this kind of stuff has been done a million time before but I'm new to this perl thing and I'm having fun.

My question is: is there a prefered way parsing XML with perl? I'd imagine that there is some cpan module out there that would do it for me, but since this program needs to run on a untouched OSX box, using a cpan module isn't possible. My plan is to write a paser function that the plugins could share... At any rate, I just wanted to get some input before I spend a bunch of time working on this.

Thanks...

Replies are listed 'Best First'.
Re: Using Perl for plugins...
by rjray (Chaplain) on Mar 08, 2002 at 01:04 UTC

    You are seriously limiting yourself by ruling any CPAN modules out. There are several different XML parsers, including SAX-based parse engines. There is nothing in the Perl core that provides XML parsing, so any solution you adopt will be either something you yourself write, or something installed from elsewhere.

    If the concern is over external dependancies (such as expat), there are a few pure-Perl parse solutions, one of which comes from matts's XML::SAX package.

    --rjray

Re: Using Perl for plugins...
by rah (Monk) on Mar 08, 2002 at 01:46 UTC
    Not sure I understand your reference to untouched OSX box or how that rules out CPAN. If you're doing Objective C, you already have the devlopmnet kit installed.

    CPAN.pm works great on OSX with the pre-installed 5.6.0 version of Perl. Unhindered, it will want to upgrade to 5.6.1, and I couldn't get this CPAN assisted build to work, but I have been using CPAN to pull down dozens of modules and every one has worked flawlessly.

    CPAN is a beautilful thing, and the CPAN.pm module and interface it provides is a work of art. There is no better way to work with CPAN modules, and with so much great code out there, no reason not to use it. If you want to develop your Perl skills by figuring out how to parse XML, by all means do. But if you'd rather move on to other things why not leverage the strength of the Perl community and grab a CPAN module to do the work for you. Then you can focus on the more interesting/challenging parts of you project.

Re: Using Perl for plugins...
by ignatz (Vicar) on Mar 08, 2002 at 12:41 UTC
    Here's how I understand your requirements:
    1. OS X
    2. No CPAN
    3. Parses XML
    This makes Perl a very bad idea since you will have to write your own XML parser from scratch and, nothing personal, but that sounds seriously ugly.

    You say that you would "like" to use perl but that it isn't a requirement. My advice is to use Java 1.4 as it has the javax.xmlpackage as a part of its core. Yes, it isn't yet available for the Mac, but you can still do the coding on an available 1.4 platform and use it on your Mac machines when that version of the JDK is ported.

    Perl without CPAN is like fries without _________ (insert favorite condiment here).

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ()-()                                                      ()-()
     \"/    DON'T   BLAME   ME,   I  VOTED   FOR    PACO!       \"/
      `                                                          ` 
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
Re: Using Perl for plugins...
by Steve_p (Priest) on Mar 08, 2002 at 13:16 UTC
    I guess I don't really understand what your asking. There are several modules capable of parsing XML. XML::Parser and XML::LibXML both have external C libraries that need to be compiled and work fine on OS X (check the Perl-XML mailing list to get the details on compiling LibXML). There are also several pure-Perl solutions. XML::SAX was previously mentioned. XML::Parser::Lite, which is included with SOAP::Lite, also works well. I would highly suggest, however, that you use an existing module rather than write your own. For what it sound's like your doing, however, you really would probably want XML::LibXSLT as well to do the conversions from XML to HTML.

    However, if this project is something that you are looking to distribute as shareware or freeware of some sort, my guess is that you are thinking in the wrong direction. While I think that it is admirable to try to come up with your own XML Parser and XML to HTML conversion routines in Perl, the two have been done many times over. Writing your own bug free routines would likely be risky at best. In a case like this, I would probably point you in the direction of an all Objective-C program, where you could compile in LibExpat or LibXML, or Java, where you could include whatever Parser and XSLT routines you wish into a JAR file.
Re: Using Perl for plugins...
by erikharrison (Deacon) on Mar 08, 2002 at 17:13 UTC

    As some people have said, your question is not exactly clear. However, I think I have a solution for you.

    As has been pointed out before, don't reinvent the wheel! Now, back when I was naive, I wrote a little faux-XML parser which handled only one specific XML document for a guestbook. It was heck, because I had to rewrite large portions of code everytime I expanded the guestbook's features. Instead of writing a XML parser from scratch, you may be tempted to write a parser just for this document. Don't.

    What may be the best solution is to tailor the wheel for your use. For example, CGI.pm uses it's own implementation of the SelfLoader, altering for it's needs and including it in the source. You could go through any of the pure Perl XML parsers mentioned above and figure out how to refit the code into yours. A simpler possibility: cut and past the whole darn thing into your code. This makes it possible to use CPAN modules when you can't use the CPAN - use the module, just package it with the plugin, either by including the file, or using a cut and paste trick. Just remember to give the original author credit!

    Cheers,
    Erik

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2025-01-24 02:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (68 votes). Check out past polls.