At 12:55 +0100 12/2/05, Serge Belleudy-d'Espinose wrote:
>I was told that for my needs perl is the way to go. If so, are there
>good resources for learning perl (I suppose so) especially when
>working on os x?
You have been told correctly.
Larry Wall is a good writer. The old "Learning Perl" and
"Programming Perl", at least ed 3, are the bibles that I keep going
back to. Both are from O'Reilly.
All true, if somewhat misleading, since Larry Wall didn't write "Learning Perl"; Randal Schwartz did. Fortunately, he's also a good writer. :)
Perl can call AppleScript via the osascript tool when you really need
to talk to a Next-Step style application.
Although that's the clunkier of the available approaches, and brings the osascript limitations to the party (such as restricted user interaction). It's a convenient leg up when you know AS but are still learning Perl; however, once you get comfortable in Perl, using native Perl modules to send and receive Apple Events is the way to go.
It can easily use other unix tools with the ` backtick) escape method.
Perl has several mechanisms for running other commands: `backticks`, system(), open("...|..."); again, though, these are often overused and, with a few exceptions depending on the command you run, are best treated as training wheels like osascript. Most of the time, you'll find that there are better ways to do whatever you want to do within Perl itself (possibly with the help of an add-on module from the Comprehensive Perl Archive Network at
cpan.org).
As for awk and sed, you'll probably never go there.
True. I'm a veteran shell programmer, and in fact resisted Perl for a long time, convinced that I could do whatever I needed with ksh, and I didn't even use awk and sed much then. Instead, I relied on shell built-ins, in the (often misguided) belief that they were more efficient. These days, I sometimes use awk and sed for quick one-offs on the command line in terminal windows, but not in programs that I'm saving to reuse. Perl's the better choice.
At this point some folks may jump in and say that you should learn Python instead of Perl. Realistically, Python and Perl (and Ruby, for that matter) occupy the same niche in the programming ecosystem, and it's valuable to learn more than one such language, of only so that the concepts don't get too tied to the syntax in your head. But I think that you should learn Perl first, and get familiar with its expressive power, before deciding - as the Python argument goes - that its too hard to read.
Personally, I'm a big fan of Ruby - which, thanks to the Ruby on Rails web application framework, its getting some mainstream attention these days. It's still a distant third behind Perl and Python in terms of popularity (which correlates to available support), but it's catching up. However, I don't recommend it as the first scripting language for someone coming from AppleScript, because Ruby is very heavily object-oriented, which is a pretty big conceptual jump. Perl is more procedural in design (albeit with object-oriented features grafted on).
Mark J. Reed <