except for the non-automagic exportation of the use constant subs

Why would you want them exported? It's easier to write accessors, or use hash keys. To export all constants (well, to export all all-uppercase-subs), you could use:

use Devel::GetSymbols; @EXPORT = grep /^[A-Z0-9_]+$/, Devel::GetSymbols::Subs;

Part of it is laziness: typing " " as opposed to "{ }", which requires a shift key.

I still find $foo{bar} easier to type than $foo[BAR]. Hashes are better for lazy people: you don't have to define a new constant every time you want to store more, and if you don't care much about style, you can skip some accessor methods too. Hashes dump better too, in case you need to debug.

Also, I was taught early in my career that array lookups are faster than perl's hashing and table-lookups.

It is true, but I still like saving minutes on coding better than saving a few nanoseconds on execution.

And I don't need to get into the autoviv. of hashes.

Exactly the same, but less inefficient if you have a lot of keys. If you set $foo[100], you'll have 100 undef values and the one you assigned to.

What are you're preferences?

Hashes, unless I need to save only one, two or three things, in which cases I use scalar or array references.

Is the speed issue that much of an issue?

Not to me. If speed were the issue, I wouldn't be coding OO anyway.

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.


In reply to Re: %hash (@array && use constant) in Modules by Juerd
in thread %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.