perlquestion
Anonymous Monk
<p>Hello Monks,<br />
I have defined a hash and assigned values to it as follows:
</p>
<code>
my(%sortListArr);
$sortListArr{'1'} = 'A1';
$sortListArr{'2'} = 'A2';
$sortListArr{'3'} = 'A3';
$sortListArr{'4'} = 'A4';
$sortListArr{'5'} = 'A5';
$sortListArr{'6'} = 'A6';
</code><p>
Then when I do a:</p>
<code>
foreach $key (keys %sortListArr){
print $sortListArr{$key},"\n";
}
</code><p>
The o/p is A1, A2....A6. However upon adding a 7th value:
</p><code>
$sortListArr{'7'} = 'A7';
</code><p>
The o/p becomes A7, A1, A2, A3...A6. Any explanations to this mystery? The problem disappears if I assign the values as:</p><code>
$sortListArr{'0'} = 'A1';
$sortListArr{'1'} = 'A2';
$sortListArr{'2'} = 'A3';
$sortListArr{'3'} = 'A4';
$sortListArr{'4'} = 'A5';
$sortListArr{'5'} = 'A6';
$sortListArr{'6'} = 'A7';
</code><p>
The o/p is then A1, A2.....A7.
</p>
Tamojit
<p><small>20050407 Janitored by [Corion]: Added formatting</small></p>
4