现在禁止标量的实验值 - perl [英] Experimental values on scalar is now forbidden - perl

查看:64
本文介绍了现在禁止标量的实验值 - perl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在旧软件中现在禁止标量的实验值:

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]) {

我试着做:

 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.

这里有更多关于@fields 对象定义的内容:

Here is more on @fields object definition:

[[
  'id',
  'entry',
  'selection',
  'status'
]]

推荐答案

这是在 Perl 5.14 中添加但在 5.23 中删除的:

This was added in Perl 5.14 but removed in 5.23:

实验性%s 标量现在被禁止 (F) 实验性Perl 5.14 中添加的功能允许每个、键、推、弹出、移、splice、unshift 和使用标量参数调用的值.这实验被认为不成功,已被删除.这postderef 功能可以更好地满足您的需求.

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]) {

这里 @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.

事实上,如果您正在访问一个项目(比如一个参考,可能在您的case) 你应该使用 $fields[0] 代替.所以首先更正一下,然后取消引用以符合 values 的标准要求(作为一个列表.它只接受标量作为实验特征过去).

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]})

这篇关于现在禁止标量的实验值 - perl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆