2

I am trying to create a settings file/configuration file. This would contain a list of key value pairs. There are 10 scripts that would be using this configuration file,either taking the input from it or sending output to it(key-values) or both.

I can do this by simply reading from and writing to the file..but I was thinking about a global hash in my settings file which could be accessed by all 10 scripts and which could retain the changes made by each script. Right now,if I use : require "setting.pl" I am able to change the hash in my current script,but in the next script the changes are not visible..

Is there a way to do this?Any help is much appreciated.

  • [Config file handling in Perl](http://stackoverflow.com/questions/5960223/config-file-handling-in-perl) – daxim Aug 14 '12 at 09:56
  • [How do you manage configuration files in Perl?](http://stackoverflow.com/questions/746972/how-do-you-manage-configuration-files-in-perl) – daxim Aug 14 '12 at 10:32

3 Answers3

2

How about a config file tied to a hash?

daxim
  • 39,270
  • 4
  • 65
  • 132
Alan Curry
  • 14,255
  • 3
  • 32
  • 33
2

Check out this module, AppConfig.

daxim
  • 39,270
  • 4
  • 65
  • 132
Sopan
  • 644
  • 7
  • 13
1

I think you need some kind of database. You can either use mysql/sqlite/etc or create a distinct script which keeps your hash and provides read/write access to it with sockets.

Danil Onishchenko
  • 2,030
  • 11
  • 19
  • 1
    A database isn't strictly needed, plain config files with simple [locking](http://p3rl.org/flock) also meet the requirement. This isn't difficult, just annoying if a programmer is used to having this automatically handled by a DBMS. – daxim Aug 14 '12 at 09:59