Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Perl / May 2006



Tip: Looking for answers? Try searching our database.

Should Mac::PropertyList read everything as UTF8

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian D Foy - 18 May 2006 00:29 GMT
I have a patch to change this vanilla file read:

  my $text = do { local $/; open my($fh), $file; <$fh> };

to this one using perlio's utf8 layer

  my $text = do { local $/; open my($fh), "< :utf8", $file; <$fh> };

Aside from differences in Perl versions (that's easy enough to handle)
and the stupidity of reading the whole file in one go, is this going to
bite me in butt with encodings? I have next to no expereince with UTF8
problems because we mostly use ASCII around here.

My main concerns are:

  * Will a plist always be utf8? For instance, what about
localizations for Japan, etc? The encoding shows up in the <?xml ...?>
portion, but am I going to have to open the file to find that, then
re-open it?

  * What happens if it's not utf8 but I tell Perl it is?

  * Will whatever I do work on another machine? I wrote this module to
read plist files on my FreeBSD machine, and I don't want to make users
have to be on a Mac (or even the same Mac) to be able to parse a file.

I have some other ideas to get around this, but my inexperience with
character encodings make me cautious (e.g. allows me to not do
anything).

  * Ignore it. A user can get the same thing by reading the file and
using parse_plist which takes a string

  * Add a parse_plist_fh method and let the user make his own
filehandles. I'm going to do that because it's a good idea, and I can
make parse_plist_file redirect to that if its arg is a filehandle.
However, the user then needs to open their own filehandle and know
things I'd like to be able to guess for them.

  * If the plist is always going to utf8, just make the change.

  * Actually hook into the Mac libraries and let the OS parse it and
give me back the data. That's the best solution, but only if I give up
being pure-Perl and portable, which are both very important to me. I
will gladly add something to do that if someone writes it for me, but
alongside the pure Perl version.

  * Can I hook into the Mac stuff with something like Inline::Java?

  * Find a sucker to take over the module and figure it out for me. As
PT Barnum said "There's a new CPAN user registered every second".
Gavin Brock - 18 May 2006 15:01 GMT
On May 18, 2006, at 8:29 AM, brian d foy wrote:

>    * Will a plist always be utf8? For instance, what about
> localizations for Japan, etc? The encoding shows up in the <?xml ...?>
> portion, but am I going to have to open the file to find that, then
> re-open it?

I guess it is really up to the file - the first line (is it always  
the first?) declares it:

    <?xml version="1.0" encoding="UTF-8"?>

Maybe you could grab the first line, parse, and then slurp the rest  
accordingly?

>    * Actually hook into the Mac libraries and let the OS parse it and
> give me back the data. That's the best solution, but only if I give up
[quoted text clipped - 3 lines]
>
>    * Can I hook into the Mac stuff with something like Inline::Java?

Actually, you can do this without resorting to Java - there was a  
great article on using the Objective-C bridge (Foundation.pm) at:

    http://www.macdevcenter.com/pub/a/mac/2005/07/29/plist.html

I had a quick hack based on this to create Mac::Tie::Plist:

    http://search.cpan.org/~gbrock/Mac-Tie-PList-0.01/lib/Mac/Tie/PList.pm

Sadly it's read only for now - been meaning to look at it again.

.. Gavin
Manfred Bergmann - 18 May 2006 15:09 GMT
Am 18.05.2006 um 16:01 schrieb Gavin Brock:

>>    * Actually hook into the Mac libraries and let the OS parse it and
>> give me back the data. That's the best solution, but only if I  
[quoted text clipped - 9 lines]
>
>     http://www.macdevcenter.com/pub/a/mac/2005/07/29/plist.html

You also can use Camelbones for reading and writing PropertyLists in  
Perl.
I use it in my build processes and it works great.

Manfred
Brian D Foy - 18 May 2006 22:05 GMT
> Am 18.05.2006 um 16:01 schrieb Gavin Brock:

> > Actually, you can do this without resorting to Java - there was a  
> > great article on using the Objective-C bridge (Foundation.pm) at:
> >
> >   http://www.macdevcenter.com/pub/a/mac/2005/07/29/plist.html

> You also can use Camelbones for reading and writing PropertyLists in  
> Perl.
> I use it in my build processes and it works great.

I saw that article too, and have been meaning to play with that stuff.
Christian Huldt - 18 May 2006 19:37 GMT
18 maj 2006 kl. 16.01 skrev Gavin Brock:

> On May 18, 2006, at 8:29 AM, brian d foy wrote:
>
[quoted text clipped - 18 lines]
>> will gladly add something to do that if someone writes it for me, but
>> alongside the pure Perl version.

Wouldn't it make sense to use some XML kit?

Or am I exposing my innocence by assuming those should take care of  
the encoding?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.