In

use constant { zed => 0, one => 1, repos => (qw(oss non-oss debug)), two => 2, };
the
{ zed => 0, one => 1, repos => (qw(oss non-oss debug)), two => 2, }
part is actually an anonymous hash constructor that passes its value (a hash reference) to the constant pragma for further processing. So this hash has to be something sensible, and
c:\@Work\Perl\monks>perl -wMstrict -MData::Dumper -le "print Dumper { zed => 0, one => 1, repos => (qw(oss non-oss debug)), two => 2, }; " $VAR1 = { 'non-oss' => 'debug', 'repos' => 'oss', 'one' => 1, 'zed' => 0, 'two' => 2 };
ain't it. As you can see,  'non-oss' ends up as a key with  'debug' as its value because  qw(oss non-oss debug) is just a flattened list within the constructor.

So no, you can't use the  { ... } version of constant as you initially wished because a valid hash must be built first.

The  use constant repos2 => qw(oss non-oss); version works because the  qw() expression is what the  repos2 function created by constant is built to return. (Update: constant distinguishes between this syntax and the  { ... } hash syntax by virtue of the type of the first argument passed to it.

c:\@Work\Perl\monks>perl -wMstrict -le "use constant [ qw(a b c d) ]; " Invalid reference type 'ARRAY' not 'HASH' at -e line 1 BEGIN failed--compilation aborted at -e line 1. c:\@Work\Perl\monks>perl -wMstrict -le "use constant qw(A b c d); print A; " bcd
)


Give a man a fish:  <%-{-{-{-<


In reply to Re: use constant; RHE of solo confusing in list by AnomalousMonk
in thread use constant; RHE of solo confusing in list by perl-diddler

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.