next up previous contents
Next: -d: Use the perl Up: Command Line Flags Previous: -p: Automatic while-loop with   Contents

-e: Execute script from the command line

The -e flag instructs the interpreter to read your perl program from the command line, instead of from a program stored in a file. Combined with the -n or -p flags, this allows some fairly sophisticated programs to be written as ``one-liners''. Generally the body of the program needs to be surrounded by single quotes on the command line. The example program to print lines with length greater than 80 from Section 1.4 could be executed from the command line as follows:
     perl -ne 'print if length > 80;'
Note the alternative form of the if statement which eliminates the need to surround the print statement with curly braces.



Phil Spector 2002-10-18