I'm trying to create a read-only "multi-dimensional" constant using the built-in constant pragma. I know that there's the Readonly module (amongst others), but I'm trying to stick to basics.

Note that core Perl has basically only one kind of inlineable constant, and that's Constant Functions, which is what constant uses, though you could just as well write sub MY_CONSTANT () { 42 } yourself. To make a list "constant" (i.e. read-only, not inlined), you will have to use some other method / CPAN module, as you said.

Personally, I used to code very defensively, i.e. make all my constants Readonly as much as I could. But after having a bit of trouble with that module, and re-reading the Camel, I now believe that the convention of simply making variables whose values shouldn't be changed all uppercase is easiest. I usually only use constants for cases where I'd like code to be conditionally optimized away, or as replacements for magic numbers.

I was under the impression that constants are really subs that I could take the reference of

Yes, in addition to being inlineable by the compiler, they are also regular subroutines. What you're seeing is simply Data::Dumper's way of showing you a code reference; see its docs for details.

Alternatively, I've tried taking direct references, but this is... just merging the lists (which is obviously bad to begin with and what I wanted to avoid by using references) in a weird "reference all elements individually" way

This is documented at the bottom of Symbolic Unary Operators.


In reply to Re: Multi-dimensional constants by haukex
in thread Multi-dimensional constants by Ionic

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.