Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Personally I'd put the initialisation of %rev_types outside the subroutine (but inside anther block to limit the scope) to avoid initialising it each time through the subroutine. But this may well smack of premature optimisation. Then again, it makes it clear that it's a constant structure.

    • I usually do that too.

      But beware. Sometimes that practise bites me when I eventually implement a class, not in it's own .pm file like I usually do, but just by switching package in the .pl file. So the variable initialization doesn't happen until afterwards and I end up with an empty data structure.

      And there is much confusion.
      • That's why you should do declaration and initialization in separate steps, and wrap the initialization with a BEGIN.

        {
            my %dispatch;
            BEGIN {
                 %dispatch = (
                     foo => sub { ... },
                     bar => sub { ... },
                     baz => sub { ... },
                 );
            }

            sub quux {