in reply to Print a hash in order
Well, you could read the perlfaq question How can I make my hash remember the order I put elements into it ?
Or, if your case is as simple as you've laid out, you could avoid the hash altogether:
# arrays preserve order. => will be treated as a comma @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' ); my $index = 0; while ($index < $#permissions-1) { ($perm_name, $perm_desc) = @permissions[$index,$index+1]; print "\nINSERT INTO permissions SET name='$perm_name', descriptio +n='$perm_desc'\n"; $index += 2; }
Updates:
|
|---|