Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
This is probably quite simple but I can't figure out why it does it...
I basically want to print the key-value pairs in the order they are written, but for some reason this does not happen.
prints out...%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', descriptio +n='$perm_desc'\n"; }
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?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 A +TMs' INSERT INTO permissions SET name='ATM_R', description='Read ATMs' INSERT INTO permissions SET name='ETM_NO', description='No access to E +TMs' INSERT INTO permissions SET name='ETM_M', description='Modify ETMs' INSERT INTO permissions SET name='ETM_R', description='Read ETMs'
Thanks for your time, dalton
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Print a hash in order
by McDarren (Abbot) on Feb 15, 2006 at 15:17 UTC | |
|
Re: Print a hash in order
by radiantmatrix (Parson) on Feb 15, 2006 at 16:01 UTC | |
|
Re: Print a hash in order
by salva (Canon) on Feb 15, 2006 at 15:28 UTC | |
|
Re: Print a hash in order
by bassplayer (Monsignor) on Feb 15, 2006 at 15:13 UTC | |
|
Re: Print a hash in order
by ww (Archbishop) on Feb 15, 2006 at 15:19 UTC | |
|
Re: Print a hash in order
by tweetiepooh (Hermit) on Feb 15, 2006 at 15:44 UTC |