in reply to Perl Riddle
Your use of strict and our is broken, however. Because they are both in a BEGIN block the scope of both is confined to just that block, making them essentially useless.
It's best to have use strict (and probably a use warnings) at the top of your code, outside of any block. The declaration for %ENGINES could be at the top, if you like, but I prefer to have the 'our' declaration near where I actually use the variable. If you intend to initialize %ENGINES at module startup then putting the declaration in a block can be a good idea.
package Data::CryptRecord; use warnings; use strict; { our %ENGINES = (...); } sub set_engine { my($self, $name) = @_; our %ENGINES; ... }
This provides some self-documentation; it's clear that %ENGINES is global. You can also initialize %ENGINES outside a block, and not have to declare it in your subroutines.
|
|---|