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.
Tamojit
20050407 Janitored by Corion: Added formatting
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.