10.2 how do I run a Perl application?

Well, a perl program is just a text file containing perl source code. At the top of a perl script is a line like this:

#!/usr/bin/perl

The file must be made executable...

chmod ug+x myscript.pl

...and must be owned by the user or group that wishes to run the script.

chown myname:mygroup myscript.pl

The script can then be invoked from the Terminal like so:

cd /script/folder
./myscript.pl


To run the perl script as an application you can drop the script onto a program called "DropScript" which converts it into an application. In this case the script should not take any arguments.

Or the script can be invoked from an application built with AppleScript Studio.

Or it can even be invoked by a Widget created for use with Konfabulator.

In fact, a perl script can be invoked by any program or utility that provides such a facility, including Cocoa applications (which is how DropScript does its magic), the Apple-provided AppleScript Menu, the Script menu of editors like BBEdit, etc. As long as the script is executable and has the correct permissions it's essentially available system-wide.

Cool, huh?

Copy this script into a file, make it executable, and invoke it from the command line. Any text you type will be spoken. Type ctrl-d to exit.

#!/usr/bin/perl -w

# Program: xspeak v1.0 (05 Jan 2002)

# Author: jshaw at sps.lane.edu (http://www.sps.lane.edu/~jshaw)
# Platform: MacOS X 10.1.x
# Synopsis: Simple PERL script that uses Applescript to speak STDIN
# Usage: "foo | xspeak" or "xspeak < filetoread" or just "xspeak" and type some text

$|++; # Flush, just in case

while(<>)
{
$args = "'say \"$_\"'";
system("/usr/bin/osascript -e $args");
}
 
Originally posted by slur

The file must be made executable...

chmod ug+x myscript.pl

...and must be owned by the user or group that wishes to run the script.

Not true. Anyone who has execute permission can run it. Do a chmod 755 or chmod a+x and anyone can run it.

You think your user owns any of the executables in /usr/bin, etc.? ;)


The script can then be invoked from the Terminal like so:

cd /script/folder
./myscript.pl


You don't have to be in the actual directory the file is in to run it. Just type the full path to it.

/script/folder/myscript.pl
 
The simplest way is to use any OSX version of BBEdit runs right from within BBEdit.
No permissions to set etc etc etc.

dave
 
in the finder.. select a *.pl file.. press comman+i to get the get-info window opened. expand the open with section..
under apps choose Launcher

then click change all.

now whenever u double click a .pl file in the finder it will execute the perl script
 
Back
Top