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

How to run a Perl script on OS X?

Honestly, I can not find the answer anywhere! Presumably, I need to run the command in the terminal, but what?

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

+46
perl macos
Apr 12 '10 at 15:45
source share
3 answers

You can run the Perl script by calling the Perl interpreter and entering your file as input:

 perl myprogram.pl 
+66
Apr 12 2018-10-12T00:
source share

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

 perl myprogram.pl 

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

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

To execute this script, you need to add execute rights to your program. Run:

 chmod +x myprogram.pl 

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

 ./myprogram.pl 
+16
Apr 12 '10 at 15:52
source share

A good Perl tutorial on OSX can be found here:

http://www.mactech.com/articles/mactech/Vol.18/18.09/PerlforMacOSX/index.html

The general documentation for executing Perl code is, of course, perldoc perlrun .

To answer your question directly:

You can run the perl script on any Unix system, either using code that has been evaluated and executed from the command line:

 perl -e 'print "Hello World\n"'; 

Or you can save your Perl script to a file (usually with the extension .pl , say script1.pl , and the first line is #!/usr/bin/perl ), and then you can execute it like any Unix program (after setting the correct permissions to fulfill)

 /path/to/script/script1.pl 

You can also execute the script from the file by running the perl interpreter as a command and providing the script as a parameter (in this case, execution permissions for the script are not needed):

 perl /path/to/script/script1.pl 
+14
Apr 12 2018-10-12T00:
source share



All Articles