Experimental values on scalar is now forbidden in old software:
$link = Winners::Links->new();
my @fields = $link->column_names;
foreach my $field ( values @fields[0]) {
I tried to make :
foreach my $field ( values {@fields[0]}) {
foreach my $field ( values %{@fields[0]}) {
foreach my $field ( values %@fields[0]) {
Non of them works. Any Idea how it should be done? Thx.
Here is more on @fields object definition:
[[
'id',
'entry',
'selection',
'status'
]]
This was added in Perl 5.14 but removed in 5.23:
Experimental
%s
on scalar is now forbidden (F) An experimental feature added in Perl 5.14 allowed each, keys, push, pop, shift, splice, unshift, and values to be called with a scalar argument. This experiment is considered unsuccessful, and has been removed. The postderef feature may meet your needs better.
So if you were using it on a reference, dereference it first. There is some confusion arriving here though because of your original code:
foreach my $field ( values @fields[0]) {
Here @fields[0]
is actually a slice, which is valid, and works. But
with strict and warnings you would get something like:
Scalar value @fields[0] better written as $fields[0] at - line x.
In fact, if you're accessing an item (like a reference, probably in your
case) you should be using $fields[0]
instead. So first correct that,
and then dereference to conform to the standard requirement for values
(being a list. It accepted a scalar only as an experimental feature in
the past).
foreach my $field ( values %{$fields[0]})
You de-reference an array using the $
sigil when you want a single value, not the @
sigil.
Try using:
foreach my $field ( values %{ $fields[0] } ) {
....
}
I've not tested, but based on written definition of an AoA reference, I think:
foreach my $field ( @{ $fields[0] } ) {...}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With