CONFIG::Hash - Class to read 2-column files into a hash


CONFIG documentation  | view source Contained in the CONFIG distribution.

Index


NAME

Top

CONFIG::Hash - Class to read 2-column files into a hash

SYNOPSIS

Top

   use CONFIG::Hash;

   my $file = CONFIG::Hash->new($filename, \%config);

   $hash_ref = $file->get();

   $value = $file->get($key);

DESCRIPTION

Top

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.

METHODS

Top

new - parse file (read via CONFIG::Plain) into hash

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

get - get a reference to the hash or a specified field

   $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.

get_line - get the linenumber where this key was found

   $line_nr = $file->get_line($key);

      Returns a scalar holding the line number. Call often to get
      include path.

get_file - get the filename where this key was found

   $filename = $file->get_file($key);

      Returns a scalar holding the filename. Call often to get
      include path.

EXAMPLES

Top

	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");'

SEE ALSO

Top

CONFIG::Plain(3pm)

The CONFIG:: Guide at http://www.fatalmind.com/programs/CONFIG/

COPYRIGHT

Top


CONFIG documentation  | view source Contained in the CONFIG distribution.