We got into a discussion during a recent 'mongers meeting about hashes, arrays, constants, speed, and autovivification. While this has been touched on recently, I continue the discussion. When constructing modules, I prefer to:
package Foo; use constant BAR =>1; use constant BAZ =>2; use constant SO_ON =>3; use constant SO_FORTH =>4; sub new { return bless ([],shift); } sub getBar { my $self=shift; $self->[BAR]; }
I picked up this style from Damien's OOP book, and like it perfectly, except for the non-automagic exportation of the use constant subs, esp. with @Bar::ISA=qw(FOO).

Part of it is laziness: typing "[ ]" as opposed to "{ }", which requires a shift key. Also, I was taught early in my career that array lookups are faster than perl's hashing and table-lookups. And I don't need to get into the autoviv. of hashes.

So I'm curious: What are you're preferences? Is the speed issue that much of an issue? And, more importantly, by using this approach, what sort of pitfalls should I be on the lookout for? Thanks!

In reply to %hash (@array && use constant) in Modules by abaxaba

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.