in reply to Re(4): Need one-liner to s///g in all sub-dirs
in thread Need one-liner to s///g in all sub-dirs

The documentation of -p omits to say that the lines are printed "to the file in question" because -p does not turn on that behavior. -p creates a loop which reads in a line into $_ with <>, executes your code, and prints $_. It prints $_ to the currently selected filehandle, which is STDOUT by default.

It's the -i switch that enables the "...to the file in question" behavior. The documentation explains that -i "specifies that files processed by the <> construct are to be edited in-place. It does this by renaming the input file, opening the output file by the original name, and selecting that output file as the default for print() statements."

Note that the -i command line switch actually takes an optional argument; an extension that is used to make a backup copy of the original file. For example, -i~ would create a backup file with a tilde at the end of the name, a la emacs.

Since -i takes an argument, perl -pie 's/old/new/g' ./*/* treats the letter e as the backup extension, and tries to open a script named 's/old/new/g'. The -i and -e switches need to be separated: perl -pi -e 's/old/new/g' ./*/*