Package DE_EPAGES::Database::API::MyIniReader
Module for working with MySQL configuration files.
Example |
my $MyIniReader = DE_EPAGES::Database::API::MyIniReader->new( FileName => 'c:/test/test.ini' ); my $Value = $MyIniReader->get( 'Section 1', 'Key 1' ); An ini file has the following structure: [Section 1] Key 1=value1 key2=value2 key3 private attributes ( for use inside this module only ): {FileName} - name of the config file {Values} - hash of sections $self->{Values}->{$Section} is a hash of key-value pairs $self->{Values}->{$Section}->{$key} is a single value |
Functions
existsSection
Returns true if the section exists in the ini file.
Syntax |
$Exists = $MyIniReader->existsSection($Section); |
Return |
|
fileName
Returns the config file name.
Syntax |
$FileName = $MyIniReader->fileName; |
Input |
|
Return |
|
get
Returns a value from the config file or $Default if the given key was not found. If the queried key is a flag without a value, undef is returned even if the flag is set. In this case, use getBool
Syntax |
$MyIniReader->get( $Section, $Key ); $MyIniReader->get( $Section, $Key, $Default ); |
Example |
$MyIniReader->get( 'mysqld', 'datadir', '/var/lib/mysql' ); |
Input |
|
Return |
|
getBool
Returns a value from the config file or $Default if the given key was not found. Returns false if the key does not exist. Returns false if the value is 0, OFF, FALSE, N or NO (case insensitive). Returns true if the value is 1, ON, TRUE, Y or YES (case insensitive). Returns true if the key has no value. Returns true if the key has another value.
Syntax |
$Value = $MyIniReader->getBool( $Section, $Flag ); |
Example |
my $Value = $MyIniReader->get( 'mysqld', 'binlog' ); |
Input |
|
Return |
|
new
Constructs a new my.ini parser object.
Syntax |
$MyIniReader = DE_EPAGES::Database::API::MyIniReader->new( FileName => $FileName ); |
Example |
$MyIniReader = DE_EPAGES::Database::API::MyIniReader->new( FileName => 'my.ini' ); |
Input |
|
Return |
|
section
Returns the specified section with key-value pairs as a hash reference. Returns an empty hash reference if the section does not exist.
Syntax |
$hSection = $MyIniReader->section( $Section ); |
Example |
$hDatabase = $MyIniReader->section( 'mysqld' ); |
Input |
|
Return |
|
sectionNames
Returns all section names found in the config file.
Syntax |
$aSections = $MyIniReader->sectionNames |
Return |
|