I found some code, on the net, on access an INI file...
I have modified it to try and assign certain values out.
Here is the code:
my ($iniFile, $UserID, $Tester, $DNS1, $DNS2, $pwd);
$iniFile = 'c:\\test.txt';
&readini;
print "Tester : $Tester\n";
print "UserID : $UserID\n";
print "Password: $pwd\n";
print "DNS : $DNS1\n";
print " $DNS2\n";
sub readini {
my ($line, $section, $key, $value, @sections);
open (INI, $iniFile) || die "could not open $iniFile - $!" ;
while ($line = <INI>) {
if (($line =~ /^\;/)||($line =~ /^\s+$/)) {
#print "Comment or Whitespace\n" ;
} else {
if ($line =~ /^\[(.+)\]/) {
#print "Section Header\n" ;
$section = $1 ;
print
"*****************************************************************\n";
print "*\n";
print "* $section \n";
print "*\n";
print
"*****************************************************************\n";
push (@sections, $section) ;
} else {
chomp $line;
($key,$value) = split(/=/, $line);
@section{$key} = $value;
if ($key == 'tester') {
$Tester = $value;
print "* $key\n";
print "* 1 tester $value\n";
} elsif ($key == 'UserID') {
$UserID = $value;
print "* $key\n";
print "* 2 $UserID value\n";
} elsif ($key == 'pwd') {
$pwd = $value;
print "* $key\n";
print "* 3 $pwd value\n";
} elsif ($key == 'DNS1') {
$DNS1 = $value;
print "* $key\n";
print "* 4 $DNS1 value\n";
} elsif ($key == 'DNS2') {
$DNS2 = $value;
print "* $key\n";
print "* 5 $DNS2 value\n";
}
}
}
}
close (INI) ;
print "*\n";
print
"*****************************************************************\n\n";
}
(Note: Comments were removed to shorten it...)
It works, almost...
The INI file is :
[User Info]
tester=John Doe
UserID=Test123
pwd=123test
DNS1=123.60.115.177
DNS2=123.60.115.152
[Hostnames]
IP=1.2.3.4
IP=4.3.2.1
IP=128.32.154.233
But I cannot get it to get past the first value...
I have tried to make sure that the =='s and ='s are proper...
Can someone help with this??
Here is the output I get, no mater what I try..
*****************************************************************
*
* User Info
*
*****************************************************************
* tester
* 1 tester John Doe
* UserID
* 1 tester Test123
* pwd
* 1 tester 123test
* DNS1
* 1 tester 123.60.115.177
* DNS2
* 1 tester 123.60.115.152
*****************************************************************
*
* Hostnames
*
*****************************************************************
* IP
* 1 tester 1.2.3.4
* IP
* 1 tester 4.3.2.1
* IP
* 1 tester 128.32.154.233
*
*****************************************************************
Tester : 128.32.154.233
UserID :
Password:
DNS :
TIA!
Chris
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]