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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.