🚀 DevOps & SRE Certification Program 📅 Starting: 1st of Every Month 🤝 +91 8409492687 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

How to read properties file using perl

scmuser created the topic: How to read properties file using perl

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

tpatil replied the topic: Re: How to read properties file using perl

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 = ;
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}

rajeshkumar replied the topic: Re: How to read properties file using perl

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
Twitt me @ twitter.com/RajeshKumarIn

Subscribe
Notify of
guest


0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x