Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run a Perl script on Mac OS X?

Tags:

macos

perl

How do I run a Perl script on OS X?

I honestly can't find the answer anywhere! Presumably I have to run a command in Terminal but what?

(I know this is a real basic and stupid question)

like image 566
Jeff Avatar asked Apr 12 '10 15:04

Jeff


People also ask

Does Mac have Perl installed?

Mac OS X already has Perl installed. Open a Terminal application (in the Utilities folder of your Applications folder) and run perl -v to find out which version. ActiveState Perl has binary distributions of Perl for Mac OS X. This is the simplest way to install the latest version of Perl.

Where is Perl on a Mac?

The path to Perl on Mac is /usr/bin/perl.


2 Answers

You can run your Perl script by invoking the Perl interpreter and giving your file as input:

perl myprogram.pl 
like image 73
codaddict Avatar answered Sep 21 '22 05:09

codaddict


The easiest way to run a perl script is with the option:

perl myprogram.pl 

However, you may find it more useful to add a shebang line at the top of the perl file.

#!/usr/bin/perl print "Hello World!\n"; 

In order to execute this script, you need to add execute permissions to your program. Run:

chmod +x myprogram.pl 

Now, in order to run your script, you can simply type:

./myprogram.pl 
like image 22
Jeff Catania Avatar answered Sep 23 '22 05:09

Jeff Catania