Wednesday, September 26, 2012

Getting value of a parameter from a property file

# Function Name    : parseDataFile
# Input            : filename with path and parameter whose value is required
# Output        : value of the the parameter from file
# Description    : This funtion will parse given file and return the value of the parameter
sub parseDataFile($$)
{
    my ($file, $parameter) = @_;
    $file = &convertSlash($file);
    open (FI, $file) or die "\nError :: :: Could not open file-${file}!!!\n";;

    while ()
    {
        my ($str) = $_;
        chomp ($str);
        $str = &trim($str);

        if ((substr($str, 0, 1) eq "#") || ($str eq ""))
        { # do nothing.  This means this line is commented or empty.
        }
        else
        {
            my $key = substr($str, 0, index($str, "="));
            my $value = substr($str, index($str, "=") + 1);
           
            if ($key eq $parameter)
            {
                return &trim($value);
            }
        }
    }
    close (FI);
    return "";
}

No comments:

Post a Comment