Chapter 2. Spacing
In this chapter, we look at various one-liners that change line and word spacing, performing such tasks as double- and triple-spacing lines in a file, removing blank lines, and double-spacing words. You’ll also learn about various command-line arguments, such as -p
, -e
, -n
, and special variables, such as $_
and $\
.
2.1 Double-space a file
perl -pe '$\ = "\n"' file
This one-liner double-spaces a file. I need to explain three things here: the -p
and -e
command-line options and the short $\ = "\n"
Perl program.
Use the -e
option to enter a Perl program directly at the command line. Typically you won’t want to create source files for every small program; with -e
you can easily write a program directly at the command line as a one-liner. ...
Get Perl One-Liners 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.