Params.pm - Parameter file parser

Access counter


SYNOPSIS

        use Params;
        my($rh_parameter);
        my($obj) = new Params("parameter_file_name");
        $rh_parameter = $obj->GetData("type_name");


DESCRIPTION

Get data from text file. This is as a common parser of data file. You can get specified type data. And you can define any type names.

That data will be got after pre-process. Pre-processor directives are defined following...

#define, #undef, #if, #elseif, #endif, #include

METHOD

PreProcess($filename [, \@buffer] )
Load from a specified file and keep pre-processed data. The $filename specify a file name of data. The \@identifier specify a reference of array that is for keep pre-processed data. If you omit a reference of array, pre-processed data will be kept in this instance.
        $obj->PreProcess("data.txt", \@buffer);

GetData($typename [, \%data, \@identifier, \@buffer])
Get a reference of hash that is data of specified type from buffer. The $typename specify type name of your wanted data. The \@identifier specify reference of array that is for keys of data. The \%data specify reference of hash that is for data.
        $obj->GetData("type", \%data, \@identifier, \@buffer);

SYNTAX OF DATA FILE

If first character of each lines is `#' and no match to directive, it will be handled as comment. If end character of each lines is `\', it continue next line. Each data define is contain one data type, one identifier and one data list. Data type and identifier is delimited by spaces. Block of data list is start with `{' and terminated with ``};''. Each data line is terminated with `;' and must be only one line.

        #comments
        type identifier{
                data-list;
                ... ;
                ... ;
        };
type : data type name
nospace character sequence

identifier :identifier
nospace character sequence

member-list : data list
        {
                nospace-character character-sequence  nospace-character;
                ... ;
                ... ;
        };

PRE-PROCESSOR DIRECTIVE

#define directive
The #define directive is given name to constant variable in data file.

#define identifier #define identifier token string

Pre-processor will replace `%identifier%' that defined by #define directive. But, it exclude comment line and replace only already defined value. Replace process is only onetime this mean can not nest define. If pre-processor can not find in define, it will search in environment variable. The identifier can include alphabet, digit number and under score.

#undef directive
Undefine identifier that defined with #define directive.

#undef identifier

#if, #elseif, #else, #endif directive
The #if directive is used with #elseif, #else and #endif directives. It flow control of data parse. If expression that following #if or #elseif directive is true, following block are valid. The #if directive have to pair with #endif. One #if - #endif pair can has any #elseif directive. The #else directive can exist up to 1 in #if block. The #if directive can nest.
        #if     expression
                strings
        #elseif expression
                strings
        #else
                strings
        #endif

In expression you can use the `defined' function.

defined(identifier)

This expression is true, if identifier is defined with #define directive or environment variable.

#include directive
The #include directive is load to current line. Also that loaded file is pre-processed.

#include file name


AUTHOR

Tetsuya Shigetome, <t_shigetome@muf.biglobe.ne.jp>.


HISTORY

$Revision: 1.1 $
$Log: Params.pm,v $ Revision 1.1 2002/04/12 14:51:34 T.Shigetome

First release of Perl module version.

 Params.pm - Parameter file parser