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

Tagged :

Creating file system info and put into mysql db

rajeshkumar created the topic: Creating file system info and put into mysql db

Create a perl script for following taskā€¦
1. Read the directory mentioned by users and list all the files along with their size and Create a property file which has following info of each file.

# Server name Path File Name date Size
1 rajesh /perforce/server:port/root xyz.txt today 10KB

2. Insert this data into mysql Db in table in same fashion as it is in property file

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

rajeshkumar replied the topic: Re: Creating file system info and put into mysql db

Hi Tushar,

I could make it for reading directory and displaying files in such a given format…

My example program is

$DIR = “/home/rajesh”;

@dirlist = `ls -l $DIR | tr -s ” ” ” “| cut -d ” ” -f5,9`;
foreach (@dirlist)
{
print “$_ \n”;
}

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

To test mysql remote server access using perl

rajeshkumar created the topic: To test mysql remote server access using perl

perl -MDBI -e ‘DBI->connect(“DBI:mysql:rajesh:rajeshk-W7″,”rajesh”,”rajesh123″) or die DBI->errstr;’

perl -MDBI -e ‘DBI->connect(“DBI:mysql:myDB:server2.whatever.co.uk”,”myuser”,”mypassword”) or die DBI->errstr;’

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

How to Open Directory and read and display all the file using perl

rajeshkumar created the topic: How to Open Directory and read and display all the file using perl

Method 1

$DIR = "/home/rajesh";
$DIRHANDLE = "HANDLE";

opendir ($DIRHANDLE, "$DIR") || die "Error Opening $DIR : $!";
@dirlist = readdir ($DIRHANDLE);
foreach (@dirlist)
{
print "$_ \n";
}

Method 2

@dirlist = `ls -A $DIR`;
foreach (@dirlist)
{
print "$_ \n";
}

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

How to identify which perl module has been installed.

scmuser created the topic: How to identify which perl module has been installed.

How to identify which perl module has been installed.

rajeshkumar replied the topic: Re: How to identify which perl module has been installed.

rmp -qa | grep perl

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

puneetbhatia77 replied the topic: Re: How to identify which perl module has been installed.

I tired this command at ubuntu but got error.

rmp -qa | grep perl
No command ‘rmp’ found, but there are 20 similar ones
rmp: command not found

DO we need to install rmp package?

Regards,
Puneet

rajeshkumar replied the topic: Re: How to identify which perl module has been installed.

Hi Puneet,

I guess ubuntu support .deb package manager by default..

you need to have RPM installed. May be following URL should help you out?
embraceubuntu.com/2005/09/23/installing-using-an-rpm-file/

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

amavila replied the topic: Re: How to identify which perl module has been installed.

Hi,
rpm or dpkg commands not to be used for listing perl modules as there are possibilities that the Perl modules are installed by downloading from CPAN web or using cpan commands.

To list perl modules –
On windows/*nix use the command: “instmodsh” (check the documentation : perldoc -i instmodsh)

If you are using Active Perl distribution you can try the command “ppm list”

Regards,
Shiva

Tagged :

Find out which perl module installed?

scmuser created the topic: find out which perl module installed?

Hi,

what is the way to find out perl module which has been installed in unix / linux system?

rajeshkumar replied the topic: Re: find out which perl module installed?

try out this?
find `perl -e ‘print “@INC”‘` -name ‘*.pm’ -print | tee ~/Perl-modules-installed.txt

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :