Monks,
I'm sure this is something stupid, but I've been staring at this code and trying things for hours on this mess.
There's obviously something wrong with my assignment to the hash on line 21, but it looks OK to me. It looks like $SubOption is being treated as a Hash reference.
As always, help is appreciated.
#! /usr/bin/perl -w
use strict;
my %data;
%data = ReadConfig("legacy.ini");
foreach my $value (values %data){
print "$value\n";
}
print "$data{MAIN}\n\n";
sub ReadConfig {
my $ConfigFile=shift;
my %Config; my $Item; my $Value;
open CONFIG,"<$ConfigFile" or die("Cannot open Config File!");
while(<CONFIG>) {
chomp;
next if ((/^#/)||(/^\s*$/));
if (/^\[(.*)\]$/) {$Item=$1;next;};
if($Item) {
my ($SubOption,$Value)=split /\=/;
if ($Value) {
print "$Item\t$SubOption\t$Value\t";
$Config{$Item}{$SubOption} = $Value;
print "-->$Config{$Item}{$SubOption}\n";
} else {
$Config{$Item} = $_;
}
}
}
close CONFIG;
foreach my $value (keys %Config){
print "->$value\n";
}
return %Config;
}
Here's the ini file....
[MAIN]
inputDir = "\\\\richnas1\\newsdata\\brides"
tempDir = C:\\Temp
textExt = .txt
imageExt = PF.tif
logfile = C:\\Temp\\brides.log
[FTP]
hostname = ftp.legacy.com
username = USERNAME
password = PASSWORD
imagedir = /timesdispatch/Celebrations/Photos/
textdir = /timesdispatch/Celebrations/
bridescap = /files1/BRIDESCAP
[E-Mail]
smtphost = inet-mail1.themeganet.com
[Notify]
rni_engineering@timesdispatch.com
And the output....
MAIN inputDir "\\\\richnas1\\newsdata\\brides" --> "\
+\\\richnas1\\newsdata\\brides"
MAIN tempDir C:\\Temp --> C:\\Temp
MAIN textExt .txt --> .txt
MAIN imageExt PF.tif --> PF.tif
MAIN logfile C:\\Temp\\brides.log --> C:\\Temp\\brides.l
+og
FTP hostname ftp.legacy.com --> ftp.legacy.com
FTP username USERNAME --> USERNAME
FTP password PASSWORD --> PASSWORD
FTP imagedir /timesdispatch/Celebrations/Photos/ --> /t
+imesdispatch/Celebrations/Phot
os/
FTP textdir /timesdispatch/Celebrations/ --> /timesdisp
+atch/Celebrations/
FTP bridescap /files1/BRIDESCAP --> /files1/BRIDESCAP
E-Mail smtphost inet-mail1.themeganet.com --> inet-mail1
+.themeganet.com
->MAIN
->FTP
->Notify
->E-Mail
HASH(0x1b8f138)
HASH(0x1b854dc)
rni_engineering@timesdispatch.com
HASH(0x1b8559c)
HASH(0x1b8f138)
Edit by castaway, removed what appear to be real username/passwords
Update
Yep, it was something stupid I was doing. When the split was happening it was leaving a trailing space on the SubOptions. I would also need to clear that up for possible indents... So I was getting $data{MAIN}{'inputDir '} Once I printed out the entire structure, it jumped right out at me. Thanks to all those who helped, sorry I wasn't more clear on the problem.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.