• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Harnessing Perl Scripts within a Project
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Harnessing Perl Scripts within a Project


  • Subject: Re: Harnessing Perl Scripts within a Project
  • From: Wim Lewis <email@hidden>
  • Date: Mon, 05 Nov 2012 12:30:56 -0800

On 4 Nov 2012, at 1:03 AM, John Delacour wrote:
> Perl is another matter altogether.  While I am getting up to speed with Obj-C I would like to be able to include Perl routines within projects, and I can find very little on the WWW to be guided by.  So far I have experimented simply with
>
>  system ("hard-coded/path/to/file")

This works, but it blocks the entire app while the script runs, and is suboptimal in some other ways. It's fine for quick&dirty use but I'd recommend using something like NSTask for a program you're going to ship to other people.

> I have not yet even attempted anything with NSTask and found no way to add Perl scripts to the project file tree and refer to them by relative path, so you can see I am not very far forward!

Perl scripts would just be ordinary resources as far as Xcode is concerned; you'd add them to the "copy bundle resources" build phase. Xcode will copy them into your .app when you build. You can then find the path to a given bundle resource at run time using NSBundle methods like -pathForResource:ofType:. (The application itself is a bundle, which can be gotten using [NSBundle mainBundle]; frameworks, plugins, and the like are also bundles.) The path is an NSString; if you're giving it to NSTask, you can pass it as-is. If you want to give the path to a POSIX API (like system() or exec()), you can convert it to an appropriate C-style string using the -fileSystemRepresentation method.  (In practice the file system representation is just UTF-8, but it's probably best to use -fileSystemRepresentation instead of hardcoding that bit of knowledge.)

Hopefully this helps you connect the dots--- all the methods I've mentioned should have more detailed info in the documentation.


It's also possible to link libperl.dylib directly into your app and use it as an embedded interpreter. I haven't tried this, though, so I don't know what problems you might hit.



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Harnessing Perl Scripts within a Project (From: John Delacour <email@hidden>)

  • Prev by Date: Re: MKMapView compositing
  • Next by Date: Re: Harnessing Perl Scripts within a Project
  • Previous by thread: Harnessing Perl Scripts within a Project
  • Next by thread: Re: Harnessing Perl Scripts within a Project
  • Index(es):
    • Date
    • Thread