in reply to Changing lots of files...

Hi arrow,
You ask:
"but i was wondering if there is a better, more efficient way of going through all the perl files and replacing a certain part in a line"
The answer is yes... don't go to the bother of going through all your files in the first place ;). What I mean by this is create a module for yourself that acts like a config file and basically allows you to change any (and all) variables from one location.

Heres the steps:

  1. Create a new text file (call it globalVars, or whatever you like...)
  2. Then type and edit the following to your needs;
package globalVars; # <- the name you chose use Exporter; @ISA = qw(Exporter); @EXPORT = qw( $PATH_FOO $URL_FOO ); # Some very good descriptive text about a path our $PATH_FOO = "/var/www/my/site/"; # Some very good descriptive text about a url our $URL_FOO = "http://www.foo.net/bar/baz.html";
  1. Now you must work out where in your system to put this file, if from the command line you type perl -e 'print join("\n", @INC);' this will give you a listing of all the directories that perl looks in for external modules. Choose one and move it there(1).
  2. Heres the hard part :(, you must now using the techniques outlined by the kind monks above replace all your hard coded paths and urls within your scripts with the var name/s you entered into your config file.
  3. Then add use globalVars; to the header of all your scripts. e.g.
    #!/usr/bin/perl -w use strict; use globalVars; ....
Once you have done that, (changed all the hard coded links into vars & added use globalVars; to all your scripts) its a simple matter of editing that text file to globally change all your vars.

Its just another TIMTOWTDI, and whilst in the short term it may seem a lot of work I'm sure you can see the advantages in so much as the next time you need to do editing, you change one file and all scripts are magically updated.

HTH ~ (well, its how I do it anyway... :)

(1) Which one you choose is up to you, everyone seems to have their favourite, you can always move it later.