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.

Note

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

One-Liners

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 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.