I ran into this, and quickly took the path of least resistance, but had something like this:
use constant {
zed => 0,
one => 1,
repos => (qw(oss non-oss debug)),
two => 2,
};
#output:
Constant name 'non-oss' has invalid characters at -e line 3.
BEGIN failed--compilation aborted at -e line 7.
Grumble. So I changed it:
tperl
use constant {
zed=>0,
one=>1,
two=>2,
};
use constant repos=>(qw(oss non-oss debug));
'
Later when I saw this section again, I forgot why I split it...and tried combining it again with same results. Tried breaking things apart, but not seeing the diffs visualized:
> tperl # (alias tperl='perl -I/home/law/bin/lib -we'\''use strict; us
+e P;')
our $k;
BEGIN{our $k={
zed => 0,
one => 1,
repos => [qw(oss non-oss debug)],
two => 2,
};}
use constant $k;
use constant repos2=>(qw(oss non-oss));'
Had to put assignment to k in BEGIN block for use-constants to see its value. But now no errors, but feeling uneasy about the result, I added some
P statement to show me the structure(s):
tperl
our $k;
BEGIN{our $k={
zed => 0,
one => 1,
repos => [qw(oss non-oss debug)],
two => 2,
};}
P "k=%s", $k;
use constant $k;
use constant repos2=>(qw(oss non-oss debug));
P "repos=%s", [repos];
P "repos2=%s", [repos2];'
#output:
k={one=>1, two=>2, zed=>0, repos=>["oss", "non-oss", "debug"]}
repos=[["oss", "non-oss", "debug"]]
repos2=["oss", "non-oss"]
Definitely a problem -- in this "solution"
sic. Repos isn't a list, but a ref to a list. Grrr.
Tried putting an array around the list:
repos => @{[qw(oss non-oss debug)]},
But then, fail:
Constant name 'non-oss' has invalid characters at -e line 10.
BEGIN failed--compilation aborted at -e line 10.
I should just give up -- not worth the hassle, but does anyone see an easy way to combine these two constant definitions so that 1 statement will suffice for 2? Don't waste too much time...since I'll have already gone to the separate definition to move
on, but sure seems a somewhat quirky situation, where because the definition in 1 def results in repos+defintion being combined with the outer list (because it is a list within a list, ala this mistake:
my ($x,$y) = (qw(1 2 3), qw(4 5 6));
Which we'd more quickly recognize as a problem if it was written:
my ($x,$y) = ( (1,2,3), (4,5,6));
Which most would see as a standard list-flattening gotcha.
Which I skimmed over when I tried to combine my constant statements due to thinking that "qw" somehow would
group them... Bzzzt. Anyway, Just don't see a safe & easy way to combine the definitions. Counterpoint?
Thanks!