Welcome, Guest
Username Password: Remember me

How to read properties file using perl
(1 viewing) (1) Guest
Perl Script
  • Page:
  • 1

TOPIC: How to read properties file using perl

How to read properties file using perl 10 months, 1 week ago #676

  • scmuser
  • OFFLINE
  • Gold Boarder
  • scm master
  • Posts: 237
  • Points: 3427
  • Karma: 0
  • Honor Medal 2009
Hi,

i would like to read properties file using perl...Any sample code or any example?

My properties file is as such ...

variable1 = value
variable2 = value

Re: How to read properties file using perl 10 months ago #677

  • tpatil
  • OFFLINE
  • Junior Boarder
  • Posts: 27
  • Points: 5105
  • Karma: 0
  • Honor Medal 2009
Hope this helps....

{code}
#! /usr/bin/perl -w
use Getopt::Long;
use strict;

my $inputFile = "test.properties";

#############################################
# Get the variables passed from property file
#############################################
my @parmList = &read_parameters;

##############################################################
# populate hash map
##############################################################
%parameters = @parmList;

#print the property1 value from test.properties
print "$parameters{"property1"}"\n"

##############################
#Subroutine to read the values
##############################
sub read_parameters {

# my $importFile = $filePath . $inputFile;
my $importFile = $inputFile;
my $parameterName = '';
my $parameterValue = '';

# open the file and read the contents into an array
open(DATA, "<$importFile") or die "\n\nUnable to open input file: $!\n\n";
my @parmListTemp = <DATA>;
close(DATA);

my @parmList = ();

foreach my $row (@parmListTemp){
chop $row;

# ignore blanks and lines that start with #
if (($row ne '') && ($row !~ /^#/)) {

# get parameters and their values and put into an array
($parameterName, $parameterValue) = split(/=/, $row);

if($debugLevel >= 3) {print "\n\n Parameter $parameterName value is $parameterValue"; };

push(@parmList, $parameterName);
push(@parmList, $parameterValue);
};
};

return @parmList;
};
{/code}

Re: How to read properties file using perl 10 months ago #680

  • rajeshkumar
  • OFFLINE
  • Moderator
  • I love software configuration management
  • Posts: 370
  • Points: 44562
  • Karma: 4
  • Honor Medal 2009
Hi Tushar,

Can you please help me on this problem

www.scmgalaxy.com/forum/perl-script/crea...to-mysql-db.html#679
Regards,
Rajesh Kumar
Build and Release Engineer
My Blog: community.scmgalaxy.com/pg/profile/rajeshkumar
  • Page:
  • 1
Time to create page: 0.92 seconds

     
    
Home Forum