Hello World in Perl


Here is the Hello World program for Perl on my MacBook. This is simpler in one way in that the Perl interpreter comes with Mac OS X without the need to download Xcode, an SDK or interpreter. However it runs within Terminal and so to do anything useful straight onto the Mac screen without using Cocoa (the OS X forms package) would be a lot of work - but watch this space! The code below is really two programs the second part outputs to a file so it does a little more than the simple Hello World. The hash character denotes a comment line.

#!/usr/bin/perl
#print "Hello World\n";
#enter the hash character using alt-3 on your Mac keyboard

$file = "a.txt";		# Name the file
open(INFO, ">$file");		# Open the file
print INFO "Hello World\n";
close(INFO);			# Close the file

Open a Terminal window and type in the program using the Nano text editor.
Start the editor with the command nano (!)

Enter the command chmod +x hello.pl to give to operating system permission to execute the file.

Execute the program with the command ./hello.pl in the Terminal window

Macinstruct - Getting started with Perl on Mac OS X

Tags - Apple MacBook Pro (13 inch, Mid 2010), OS X Yosemite Version 10.10.1, Perl, Hello World, Macinstruct,