Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I have defined a hash and assigned values to it as follows:
my(%sortListArr); $sortListArr{'1'} = 'A1'; $sortListArr{'2'} = 'A2'; $sortListArr{'3'} = 'A3'; $sortListArr{'4'} = 'A4'; $sortListArr{'5'} = 'A5'; $sortListArr{'6'} = 'A6';
Then when I do a:
foreach $key (keys %sortListArr){ print $sortListArr{$key},"\n"; }
The o/p is A1, A2....A6. However upon adding a 7th value:
$sortListArr{'7'} = 'A7';
The o/p becomes A7, A1, A2, A3...A6. Any explanations to this mystery? The problem disappears if I assign the values as:
$sortListArr{'0'} = 'A1'; $sortListArr{'1'} = 'A2'; $sortListArr{'2'} = 'A3'; $sortListArr{'3'} = 'A4'; $sortListArr{'4'} = 'A5'; $sortListArr{'5'} = 'A6'; $sortListArr{'6'} = 'A7';
The o/p is then A1, A2.....A7.
Tamojit20050407 Janitored by Corion: Added formatting
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Mysterious hash behaviour
by ysth (Canon) on Apr 07, 2005 at 06:57 UTC | |
Re: Mysterious hash behaviour
by Zaxo (Archbishop) on Apr 07, 2005 at 06:57 UTC | |
Re: Mysterious hash behaviour
by borisz (Canon) on Apr 07, 2005 at 07:01 UTC | |
by tsam (Novice) on Apr 07, 2005 at 07:06 UTC | |
by Limbic~Region (Chancellor) on Apr 07, 2005 at 13:26 UTC | |
Re: Mysterious hash behaviour
by davido (Cardinal) on Apr 07, 2005 at 07:02 UTC | |
by Anonymous Monk on Apr 07, 2005 at 08:15 UTC |
Back to
Seekers of Perl Wisdom