CONFIG::Hash - Class to read 2-column files into a hash
use CONFIG::Hash; my $file = CONFIG::Hash->new($filename, \%config); $hash_ref = $file->get(); $value = $file->get($key);
Parses a two-column formated file into a hash. The module uses the CONFIG::Plain class so you can use all features of the Plain module.
Configuration Options:
-> all described in CONFIG::Plain are known KEYREGEXP Scalar holding a regular expression which must match every key. DEFAULT: "^(\\S+)" HINT: Since the first character of a line has to be a non-white-space character it is possible to make multi-line values. Have a look at the examples. HASHREGEXP Scalar holding a regular expression which matches the content. DEFAULT: "\\s+(.*)\$" SUBSTITUTENEWLINE If defined all NewLine characters in the value will be substituted with this scalar. DEFAULT: "\n" REQUIRE Reference to a Array which holds list of required variables. DEFAULT: [] DEFAULT Reference to Hash holding default Values. DEFAULT: {} ALLOWREDEFINE Scalar switch to suppress error messages if the same key is redefined at a later point in file. DEFAULT: 1 CASEINSENSITIVE All keys are convertet into lower case if this option was defined. DEFAULT: undef
$hash_ref = $file->get(); Returns a reference to the hash holding all data from file. $value = $file->get($key); Returns the value to the specified key.
$line_nr = $file->get_line($key); Returns a scalar holding the line number. Call often to get include path.
$filename = $file->get_file($key); Returns a scalar holding the filename. Call often to get include path.
Assumes default configuration >KEY This is a very stupid text > but it shows the functionality \ > of this module Will get into 'KEY' => "This is a very stupid text\nbut it shows the functionality of this module" With the config setting 'SUBSTITUTENEWLINE' => ' ' >INSERT insert into > table dummy > (col1, col2, col3) > values > (1, "value", "value2"); Will get into 'INSERT' => 'insert into table dummy (col1, col2, col3) values (1, "value", "value2");'
CONFIG::Plain(3pm)
The CONFIG:: Guide at http://www.fatalmind.com/programs/CONFIG/
Copyright (C) 1999, 2000 by Markus Winand <mws@fatalmind.com> This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install CONFIG::Hash, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CONFIG::Hash
CPAN shell
perl -MCPAN -e shell install CONFIG::Hash
For more information on module installation, please visit the detailed CPAN module installation guide.