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' ./*/*


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.