P is for Practical | |
PerlMonks |
Re^2: Update config file parametersby afoken (Chancellor) |
on Jan 07, 2016 at 21:38 UTC ( [id://1152253]=note: print w/replies, xml ) | Need Help?? |
You can do inplace editing of files: But that introduces a race condition. The problem is documented in perlrun:
The race: Instance 1 is started, reads the configuration file, then starts rewriting by renaming the configuration file and creating a new, still empty (or partly written) configuration file. Instance 2 is started, and reads an empty (or partly written) configuration file. How to get rid of that problem:
(Note that safely creating temporary files is another problem: mkstemp(3) and tmpfile(3) should be safe. mktemp(3) and tmpnam(3) aren't. File::Temp has safe and unsafe functions.) Alexander (And yes, the problem of "disappearing configuration data" has bitten me once, and it was quite hard to find.)
-- Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
In Section
Seekers of Perl Wisdom
|
|