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.
In reply to Too much Hash?? by HamNRye
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |