Okay, I'm lost on this...I thought I finally had the solution to using a reference to an element of an array in a foreach loop, but now I have a stranger problem. Any help would be appreciated.
In this hash I create my list of subroutines I wish to call and a descriptive name for them - they will be elements in a menu in a Perl Tk script:
my %choices = (
'fs_sub' => 'File Systems',
'mem_sub' => 'Memory'
);
Further in the script I attempt to call the list in a foreach loop:
foreach (keys(%choices)) {
$choice_menu->command(-label => $choices{$_},
-activebackground => '#CCCCCC',
-command => \&$_);
}
All seems to work, except that the second (last) set of keys/values in the hash is repeated. Or more appropriately, the foreach loops twice on the last set, giving me:
File Systems
Memory
Memory
...in my menu.
Any ideas why it is doing this?
Kickstart
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.