perlquestion
Anonymous Monk
Hiya,
<p/>
This is probably quite simple but I can't figure out why it does it...
<p/>
I basically want to print the key-value pairs in the order they are written, but for some reason this does not happen.
<code>
%permissions = ('ATM_NO' => 'No access to ATMs',
'ATM_R' => 'Read ATMs',
'ATM_W' => 'Write ATMs',
'ATM_M' => 'Modify ATMs',
'ATM_D' => 'Delete ATMs',
'ETM_NO' => 'No access to ETMs',
'ETM_R' => 'Read ETMs',
'ETM_W' => 'Write ETMs',
'ETM_M' => 'Modify ETMs',
'ETM_D' => 'Delete ETMs' );
while (($perm_name, $perm_desc) = each(%permissions))
{
print "\nINSERT INTO permissions SET name='$perm_name', description='$perm_desc'\n";
}
</code>
prints out...
<code>
INSERT INTO permissions SET name='ATM_D', description='Delete ATMs'
INSERT INTO permissions SET name='ATM_W', description='Write ATMs'
INSERT INTO permissions SET name='ATM_M', description='Modify ATMs'
INSERT INTO permissions SET name='ETM_W', description='Write ETMs'
INSERT INTO permissions SET name='ETM_D', description='Delete ETMs'
INSERT INTO permissions SET name='ATM_NO', description='No access to ATMs'
INSERT INTO permissions SET name='ATM_R', description='Read ATMs'
INSERT INTO permissions SET name='ETM_NO', description='No access to ETMs'
INSERT INTO permissions SET name='ETM_M', description='Modify ETMs'
INSERT INTO permissions SET name='ETM_R', description='Read ETMs'
</code>
Why is it in that order? It doesnt appear to be related to the values or alphabetical in any way, it also seems to be consistent across other hashes as well. Sorting them will not work as an order different to the one written will be generated, does anyone have any ideas?
<p/>
Thanks for your time, dalton
2