Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you manage configuration files in Perl?

I have a program that has to read a configuration file from a PHP script, and a quick search has revealed there are dozens of ways to handle configuration files in Perl:

  • Config data in a separate file
  • AppConfig
  • Config::General
  • Config::IniFiles
  • Config::Scoped
  • Config::Simple
  • ConfigReader::Simple
  • And many others

Brian provides an overview here.

Config::Simple will work for me, since the existing file is INI-like. I am interested to know what style people regularly use in their code though?

like image 669
Anon Gordon Avatar asked Apr 14 '09 10:04

Anon Gordon


People also ask

How do I read a Perl config file?

The line that reads and parses the configuration file is Config::Tiny->read. It returns a reference to a 2-dimensional hash. The main hash has the sections as keys and the values are the hashes representing each individual section. We can then access the specific values using the $config->{section}{key} construct.

What can you do with configuration files?

Configuration files can be used for a wide range of reasons, though they are mostly used by operating systems and applications to customize the environment. Configuration files are used for operation system settings, server processes or software applications.


1 Answers

I quite like using YAML configuration files. I find them to be very readable and easily manipulated. They fit naturally into Perl as well as the primary constructs are Arrays and Hashes.

like image 199
Adam Pope Avatar answered Oct 12 '22 11:10

Adam Pope