This will show you what is happening.for (keys(%{$ini{$hostnames[$i]}})) { print "Slot: $_\n"; push @slots,$_; print "IfIndex: ${$ini{$hostnames[$i]}}{$_}\n"; push @ifindices,${$ini{$hostnames[$i]}}{$_}; }
Let's split the lines: $hostname[$i] contains your hostname. This is used as a key for the %ini - hash. So we could simplify it for better understanding as
$Hostpart_from_INI contains a reference to what Config::INI found for this hostname (the one for the current loop run). It is a Hash-Reference, so we could also write:for (keys(%{$Hostpart_from_INI})) {
Okay, now we're here with a simple Hash. Each loop run gets another key from the Hash %Host_Data_from_INI. If you got Problems with $_, we could add it:for (keys(%Host_Data_from_INI)) {
You should try the following for better understanding:for $_ (keys(%Host_Data_from_INI)) {
You could also add the $_ behind the for or you could use any other variable.perl -le 'for (1,2,3) { print $_; }'
Remember: We changed nothing, the code is still the same. All we did was renaming things and solving references to show what Perl sees when executing the script.for (keys(%Host_Data_from_INI)) { push @slots,$_; push @ifindices,$Host_Data_from_INI{$_}; }
In reply to Re^3: Ini files
by Sewi
in thread Ini files
by Ravendark
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |