In
theuse constant { 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{ zed => 0, one => 1, repos => (qw(oss non-oss debug)), 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.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 };
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.
)
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |