Reputation: 11
I am trying to debug a Perl script that is giving me the error
Experimental keys on scalar is now forbidden
This seems to be an issue my system having a newer version of perl, but was hoping some can sugegst a quick fix.
The line in question is
foreach my $elemName(keys $grammar -> {$groupName})
grammer was defined as
my $grammar = {};
and groupName comes from
foreach my $groupName (keys %$grammar)
I do not know much about perl, so any help would be appreciated
I have a similar issue with this line
push($DbRef->{def_param}{$par_descr}->{dataset}, $blkDs);
with error Experimental push on scalar is now forbidden ... near "$blkDs)"
I have tried some solutions I have found about dereferencing, but the syntax is very confusing to me.
Upvotes: 1
Views: 740
Reputation: 386331
keys EXPR
and push EXPR, LIST
were introduced in 5.14 as an experimental feature.
keys EXPR
and push EXPR, LIST
started warning in 5.20 when the concept of warnings for experimental features was introduced.
keys EXPR
and push EXPR, LIST
were removed in 5.24 as the experiment was deemed a failure. (The design of keys EXPR
is fundamentally flawed.)
To get the keys of hash, you can use keys %NAME
. You can also use a hash deference, such as keys %BLOCK
or keys EXRP->%*
.
To get the indexes of an array, you can use keys @NAME
. You can also use an array deference, such as keys @BLOCK
or keys EXRP->@*
.
To push scalars onto an array, you can use push @NAME, LIST
.
You can also use an array deference, such as push %BLOCK, LIST
or push EXRP->@*, LIST
.
In your case, you want
keys %{ $grammar -> {$groupName} }
or
keys $grammar -> {$groupName} -> %* # 5.24+
and
push(@{ $DbRef->{def_param}{$par_descr}->{dataset} }, $blkDs);
or
push($DbRef->{def_param}{$par_descr}->{dataset}->@*, $blkDs); # 5.24+
Upvotes: 3