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.


In reply to Re: Changing lots of files...(TIMTOWTDI) by barrd
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.