You're probably doing a lot more work in Perl than you really have to do. Try leveraging the power of command line tools to your advantage. I bet you could do what you want with a single command line.

find /path/to/dir -name '*.pm' | xargs perl -i.bak -n -e 's/original/n +ew/; print;'

The find command is going to spew out a list of files. The xargs command is going to invoke perl with the switches specified, and drop the list of files on the end of the command line. For perl: the -i switch specifies in place editing, and copies the originals to files with the .bak extension added; -e specifies the code you're going to execute; -n specifies an implicit while (<>) { ... } around the stuff specified by -e.

I am constantly amazed by the incredible power that I can wield with a single, well constructed command line. However, as an addendum, your initial statement, "I need to go through a large amount of perl files to change certain paths and urls contained in them", makes me curious... Could you have created a common file that contained constants that all of your scripts might have included? It sounds like you might have committed the cardinal sin of hard coding constants all over your code, when a single hard coding and then repeated reference thereto would have been a far more maintainable solution.


In reply to Re: Changing lots of files... by skyknight
in thread Changing lots of files... by arrow

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.