Lets break the '.*/*' approach down a bit, to help you understand the difference between the two

perl -pie 's/old/new/g' ./*/*
The first thing that happens when you enter this command into your shell, is that the shell expands the wildcards. This is important.... perl doesn't ever see the './*/*' construct. The shell then executes the expanded command which now looks like:
perl -pie 's/old/new/g' subdir/file1 subdir/file2 subdir2/file1 subdir +2/subsubdir/
And perl does its magic inplace editing on this list of files. (note, see the update to my previous post) No recursion is done. You've simply said, execute this perl command on the following files. Those files being ones that the shell matched with its './*/*' pattern.

In otherwords, you could use that command like so:

perl -pi -e 's/old/new/g' file1 dir1/file2 /usr/local/file3 /tmp/*
You've passed the perl command a set of files which it will work with. (thats what the empty <> operator does that you've seen in the perlrun docs)

On the other hand, the find solution will walk the filesystem executing the perl command on each file that matches its criteria (here its just </code>-type f</code> which means a regular file) Depending on your filesystem layout, this can be much more powerful than the other solution.

Said another way... the find solution is equivalent to the following series of commands:

perl -pie 's/old/new/g' ./* perl -pie 's/old/new/g' ./*/* perl -pie 's/old/new/g' ./*/*/* perl -pie 's/old/new/g' ./*/*/*/* perl -pie 's/old/new/g' ./*/*/*/*/* etc.....
Of course you'll get errors about executing the command on directories, and you'll soon hit your shells 'too many arguments' limit. Therefore find is a better general solution, but './*/*' might work fine in any one instance.

-Blake


In reply to Re: Re: Re: Re: Re: Re: Re: Need one-liner to s///g in all sub-dirs by blakem
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.