in reply to Changing lots of files...

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.

Replies are listed 'Best First'.
Re: Re: Changing lots of files...
by Hofmator (Curate) on Jul 24, 2003 at 07:16 UTC
    or even ... perl -i.bak -pe 's/original/new/' see perldoc perlrun

    -- Hofmator

      Indeed, you have done me one better. I shall have to remember that.
Re: Re: Changing lots of files...
by Skeeve (Parson) on Jul 24, 2003 at 13:00 UTC
    better use
    s(/old/path)(/new/path)g
    to avoid the LTS (leaning toothpick syndrome)
Re: Re: Changing lots of files...
by arrow (Friar) on Aug 07, 2003 at 02:58 UTC
    I am sure that that would work, but I wouldn't know, my scripts are all for the internet, thus I can only interact with them with a browser.

    Just Another Perl Wannabe