Another Example: Create Hello World As a Script

Now let's do the same thing, only this time we'll create Hello World as a separate file and execute the script that way. You'll need a text editor. Not a word processor, but specifically an editor just for text: emacs, vi, or pico are just fine for Unix; use Notepad or the shareware programs TextEdit or UltraEdit on Windows; you can use SimpleText BBedit or any of the mentioned Unix tools on Mac OS X.

Create Hello World as a Script

Fire up your text editor and type the two lines shown in Listing 1.1 (well, three if you count the blank one in the middle).

Listing 1.1. The hello.pl Script
1: #!/usr/bin/perl -w
2:
3: print "Hello, World!\n";

Note

Don't type the numbers at the beginning of the lines ...

Get Sams Teach Yourself Perl in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.