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:
- Create a new text file (call it globalVars, or whatever you like...)
- 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";
- 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).
- 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.
- 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.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.