CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Faster Configuration files

 



tallest1
Deleted

Jul 31, 2000, 1:16 PM

Post #1 of 6 (1566 views)
Faster Configuration files Can't Post

To manage my scripts' configurations, I have a text file w/ a variable in each line (15-18 variables) and then a script that assigns each line to a variable (eg. $name = $line[3] Wink

At the moment it works fine but I'm concerned about its efficiency and loading time. The script which opens the config file and sets the variables is exectuted VERY VERY often and I'd hate to see it slow down the very scripts that rely on it. Do you know of any faster, more efficient ways to create/manage script configurations?
Thanks in advance

------------------
Focus Web Services - Auto Updater


Kanji
User / Moderator

Jul 31, 2000, 3:02 PM

Post #2 of 6 (1566 views)
Re: Faster Configuration files [In reply to] Can't Post

Persistance through something like mod_perl will make things truely fast (ie, load configs once, keep them in RAM until the config file changes), but if that's not an option, you could try ...

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

require '/path/to/config.pl';</pre><HR></BLOCKQUOTE>

... and in config.pl ...

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

%CONFIG = (
"name" => "...",
"email" => "...",
"ad nauseum" => "...",
);
1;</pre><HR></BLOCKQUOTE>


tallest1
Deleted

Jul 31, 2000, 4:00 PM

Post #3 of 6 (1566 views)
Re: Faster Configuration files [In reply to] Can't Post

Sorry, I forgot to mention that I need a type of config file w/ variables that can be edited by the script itself. Thats why I use variables in each line of a text file. Its easy for the script to modify it.

P.S. - Is there any info on modperl anywhere?

Thx for your feedback though.


------------------
Focus Web Services - Auto Updater


Kanji
User / Moderator

Jul 31, 2000, 6:06 PM

Post #4 of 6 (1566 views)
Re: Faster Configuration files [In reply to] Can't Post

Why would modifying a perl script be any more difficult than modifying any other text file? The only thing I'd worry about is trying to require the file while overwritting it, but that's what flock is for.

As for mod_perl, see http://perl.apache.org/ .


tallest1
Deleted

Jul 31, 2000, 8:33 PM

Post #5 of 6 (1566 views)
Re: Faster Configuration files [In reply to] Can't Post

Are you saying that I should have the script actually open and modify another script?!


Kanji
User / Moderator

Jul 31, 2000, 9:54 PM

Post #6 of 6 (1566 views)
Re: Faster Configuration files [In reply to] Can't Post

Why not? As far as your script is concerned, it's just another text file to manipulate. Smile

Heck, here's a very rudimentary self-modifying, self-executing script!

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

#!/usr/bin/perl -w

local( $^I, @ARGV ) = ( ".bak", $0 );

while ( <> ) {
s/(\d+);/ $1+1 . ";" /e if /\d+ \*\*/;
print;
}

my $no = 2 ** 0;
print $no, "\n";

exec $0 unless $no > 128;
unlink "$0.bak";</pre><HR></BLOCKQUOTE>

Error checking left as an exercise for the reader. :-)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives