Is there a way to get the system configuration files folder within a Perl script? -


tried searching number of ways , have not yet found answer ...

background

i working on legacy perl application has lot of hard-coded values in should configurable depending on app installed. so, obviously, looking externalize these values configuration file may located in 1 of few "expected" locations. is, using traditional approach of checking configuration file in:

  • the current working directory,
  • the user's home directory (or sub-folder therein), and
  • the system configuration directory (or sub-folder therein)

where first 1 found wins.

where at

perused cpan site bit , found config::any package, looks promising. can give list of files use:

use config::any; $config = config::any->load_files(     {         files => [qw(sample.conf /home/william/.config/sample.conf /etc/sample.conf)],         use_ext => 0,     }); 

this check existence of each of these files, and, if found, load contents array reference of hash references. not bad, still have hard-code locations search sample.conf file. here, assume working on linux system, , location configuration file users of application /etc/. add /usr/local/etc/ well, regardless, not system agnostic.

i can locate user home folder using file::homedir searching there, , works correctly regardless of system on application running. there similar package provide /etc/ folder (or equivalent on other platforms)?

questions

  • is there way without having know particular os on? (perl package or code snippet)
  • what "perl best practice" way of accomplishing this? cannot imagine no 1 else has run previously.

unless don't plan run code on non unix-based hosts, according conventional directory layout , filesystem hierarchy standard, may rely on quite large set of known places.

anyway, nothing prevents dynamically build file search specification take account of platform oddities , specific ways them (eg. file::homedir::win32 vs file::homedir).


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -