Other Command-Line Stuff

The debugger isn't the only feature of the Perl interpreter that can be activated by command-line switches. In fact, many useful Perl programs can be written just at the command prompt.

By the Way

Macintosh users should run these command-line examples by selecting 1-liners from the Script menu and then typing the command in the dialog box.


The key to such programs is the -e switch given to Perl on the command line. Following the -e can be any Perl statements at all, as in this example:

C:\> perl -e "print 'Hello, world';"
Hello, world

You can use multiple -e statements to insert multiple statements or separate them with semicolons, as shown here:

C:\> perl -e "print 'Hello, world';" -e "print 'Howzit goin?'" ...

Get SAMS Teach Yourself Perl in 24 Hours THIRD EDITION now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.