| Developer's Daily | Perl Education |
| front page | java | perl | unix | dev directory | web log |
Introduction
Way back in the stone age (er, the 1970's) when Kernighan & Ritchie first created the C programming language, they introduced it to the world in the famous white book with their "Hello, world!" example.
After all these years, it still seems like a good way to introduce a
programming language, so here's our version of "Hello, world!", written
in Perl:
| #!/usr/local/bin/perl
print "Hello, world!\n"; |
| Listing 1: | The source code for the "Hello, world!" program. |
Discussion
The first line of the program specifies the location of the Perl interpreter. On Unix servers, the Perl program is usually installed in the /usr/local/bin directory. This special syntax is the proper way of indicating to a Unix operating system that it should use this interpreter to read the next lines of code.
The second line of the program is a simple Perl print statement that prints out the now-famous phrase. When you run this program from the command-line, the words "Hello, world!" are printed to your screen (followed by a carriage-return).
That's the whole program for this simple example. Just save these
two lines of code to a file named hello. Then, to run the program
on a Unix system, you'll need to make the program executable. You
can do this with the chmod command:
| chmod +x hello |
| hello |
Note: If your current directory isn't in your path, you'll need
to (a) change your PATH variable, or (b) run the program like this:
|
Final thoughts
We hope this simple Perl program leads you along the road of learning
a terrific programming language. With Perl you'll be able to accomplish
great things with a little bit of code in a short time!
Copyright © 1998 DevDaily Interactive, Inc.
All Rights Reserved.