Perl - Parsing Property Lists?

1.3k views Asked by At

Which is the best method for parsing Mac property lists with Perl? I'm trying to write a script that will parse plists containing various arguments, including some nested within layers of containers (arrays in dictionaries, or dictionaries in dictionaries).

As far as I can tell, there 's a few options:

  • Mac::PropertyList module on CPAN. However, it's quite low-level and this warning gives me pause:

You probably shouldn't use this in applications--build interfaces on top of this so you don't have to put all the heinous multi-level object stuff where people have to look at it.

  • I have the option to convert the plists into another format, so I'm also considering using an XML parser module, as well. I'm not sure which would be the best in this situation.

  • I've also read that that plists can be converted into JSON in OS X 10.7, so if there exists good Perl libraries for parsing JSON, I'm open to that too, as long as it isn't too much of a headache dealing with nested entries.

Any suggestions?

Update: At this point I'm highly leaning towards the JSON option, just because it's likely less of a headache than XML.

2

There are 2 answers

1
daxim On BEST ANSWER
0
David W. On

How good are you at Perl?

In CPAN, there's a module called Mac::PropertyList that might do exactly what you want. I've never used it, but you can try playing with it.

If you can use XML, then use XML::Simple. I've use this module all the time for parsing and building XML files. With XML::Simple, parsing XML files is very easy to do.

There's a JSON module in CPAN, but I've never used it, and I'm not sure whether or not it will help you.

Have you used CPAN modules before?