There's an interesting issue I ran into, not for the first time:
My module contains some hash that maps data. It is constant and is changed only by the programmer, for example:
my %opcode_map = ( 'LDA' => [8, 0], 'STA' => [14, 1], ... ... );
The 'my' makes this map private to the module, as it should be (only functions from the module use it, it's never exported). However, when a table contains many duplications that can be generated automatically, I'm not sure what is the best way to generate the entries.
For instance, there are keys 'LD1', 'LD2', ... up to 6, with the opcode also having a pattern which can be easily generated. So, instead, I place 'LDi" and then a loop replaces each i by 1..6 and adds all the relevant entries into the map.
In the past, I just slapped the code "in the wild" in the module's scope. It runs when the module is "use"-d, and that's it. However, it doesn't look "clean" to me, and I wonder whether ther are better ways ?
In reply to code that runs at module loading by spurperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |