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:
- 2006-02-15 : Thanks to rinceWind, salva, and wfsp for pointing out that I neglected to increment $index. *blush* It's fixed now.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.