in reply to Running Perl Scripts on a Mac?

You can put the scripts wherever you like on your system. However, the location should be in your PATH environmental variable, or you'll have to type the complete path to your file.

In addition, you need to make sure the files have execute permissions and that they include the shebang line as the first line (#!/usr/bin/perl) in the file.

Once you've done that, you type perl scriptname.pl on the command line in the terminal. That's all you need. :)

HTH,

/Larry

Update: Fixed a couple of typos. :)

Replies are listed 'Best First'.
Re^2: Running Perl Scripts on a Mac?
by jhourcle (Prior) on Mar 15, 2005 at 00:32 UTC

    One more typo -- you'd type scriptname.pl after you've followed the rest of your instructions. As with any other perl box, you can run scripts one of two ways from the command line:

    Placing the files in your $PATH.
    If you want to call the file as the name of the file (eg, 'script.pl', then you'll want to use the first two paragraphs -- place the file in your $PATH, make sure it has execute (chmod u+x script.pl), and the proper shebang line... but you call it without calling perl on the command line.
    Calling the perl executable with an argument.
    This will not search your path, and will only search your local directory (or whatever path you specify. When called this way, you need perl in your path, but not the script. Also, the script doesn't need a shebang line, or be executable.

    Update: if you want to make sure perl is in your path, type which perl at the command line. It's installed by default at /usr/bin/perl (but without critical header files that are needed to build new modules, at least in 10.3 server, as I found out today).

Re^2: Running Perl Scripts on a Mac?
by Spidy (Chaplain) on Mar 14, 2005 at 22:14 UTC
    so, how would I go about finding out what's in my $PATH variable, using a one-liner?

      Open Terminal, and type the following at the commahd line:

      echo $PATH

      Letter case counts. :) Terminal will return a colon-separated string that contains your path information. You could put your scripts into any of the directories listed, however, I would recommend that you create a 'bin' directory in your Home directory and put your scripts there. Then, to execute your scripts, you'd type the following on the command line:

      perl $HOME/bin/scriptname.pl

      or

      perl /Users/yourusername/bin/scriptname.pl

      You can add directories to your PATH variable, but I'll leave that exciting task to you. (Hint: On the command line, type man bash.) :)

      HTH,

      /Larry