You didn't say what is going wrong with your code.
I suggest adding this after tie'ing the ini-file:
use Data::Dumper;
print Dumper(\%ini)."\n";
And you have two typos:
push @slots, keys%{$ini{'$hostnames[$i}'}};
push @ifindices, values%{$ini{'$hostnames[$i}'}};
The closing bracket for [ should be ] instead of }
The ' chars within $ini{} make Perl treat this as a string and I don't think that there is a [$hostnames[$i}] - block in your file :-) Just remove the ' there.
These things are usually very hard to find expecially if you're working on a piece of code for a longer time without breaks. Usually, I add a print in those cases and _copy&paste_ the variables which don't work there. If you re-type them, you may loose some typos and will get even more confused.
Please remember, that keys() and values() don't return the same order of items, so you won't get any associations between slots and ifindices. Try
for (keys(%{$ini{$hostnames[$i]}})) {
push @slots,$_;
push @ifindices,${$ini{$hostnames[$i]}}{$_};
}
Last note:
If you don't really need $i, you could advoid it:
for (@hostnames) { print $_; }
In this loop, $_ is the same as $hostnames[$_] in your loop. For nested loops:
for my $Hostname (@hostnames) { print $Hostname; }
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.