Writing/Executing a Simple Perl Script

Every programming course I have ever taken begins with designing a “Hello World” program. This chapter is no exception. We can begin by running a Perl script explicitly from the command line. Assuming that the location of the Perl executable is in your path, the following program

perl -e 'print "Hello world!\n";'

prints the following output:

Hello world!

The -e tells Perl to execute the quoted Perl code that follows on the command line. This method is only for short programs that fit on the command line.

See Table 29.1 for other standard properties of the perl command.

Table 29.1. Other Properties of the perl Command
PropertySee page
Allows relative and absolute pathname arguments70
Processes either filename ...

Get Practical UNIX 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.