如何重写给定/何时消除“实验”警告使用
所有这些,
我有以下内容:
This is perl 5, version 26, subversion 3 (v5.26.3) built for x86_64-linux-thread-multi
(with 57 registered patches, see perl -V for more detail)
Copyright 1987-2018, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
当我使用的脚本为和时,> 。
Trying to Google I found this ,这说它将以不兼容的方式进行更改。
我在Rhel8上,前进。
我想修复脚本,以便其他脚本也可以利用脚本,而不再看到这些警告。
如何重写它以摆脱警告?
蒂亚!
编辑:
很抱歉没有足够明确 - 通过修复脚本,我的意思是消除有问题的呼叫/重写。
edit2:
given($pl) {
when(0) { print "A"; }
when(1) { print "B"; }
when(2) { print "C"; }
when(3) { print "D"; }
when(4) { print "E"; }
default { print "Illegal "; }
}
其中$ pl
只是一个整数(C中的无符号简称)。
该脚本从文件中读取一些数据。 该文件包含一些十六进制值。这些值是解析的 - 提取了一些位,然后将这些位的字符串表示形式打印在屏幕上。
EDIT3:
我尝试使用以下代码:
my %table_pl = (
0 => sub { print "A"; },
1 => sub { print "B"; },
2 => sub { print "C"; },
3 => sub { print "D"; },
4 => sub { print "E"; },
);
for $pl( 0..5 )
{
if( exists $table_pl{$pl} )
{
$table_pl{$pl}->();
}
else
{
print "Illegal ";
}
}
但是我有一个错误:
Number found where operator expected near 1
(Missing semicolon on the previous line?)
ALL,
I have following:
This is perl 5, version 26, subversion 3 (v5.26.3) built for x86_64-linux-thread-multi
(with 57 registered patches, see perl -V for more detail)
Copyright 1987-2018, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
And the script I'm using have given
and when
.
Trying to Google I found this, which says it will be changed in an incompatible way.
I'm on RHEL8 and moving forward.
I'd like to fix the script, so that other get advantage of the script as well and don't see those warnings anymore.
How do I rewrite it to get rid of the warning?
TIA!
EDIT:
Sorry for not being explicit enough - by fixing the script I meant eliminating the problematic call/rewriting it.
EDIT2:
given($pl) {
when(0) { print "A"; }
when(1) { print "B"; }
when(2) { print "C"; }
when(3) { print "D"; }
when(4) { print "E"; }
default { print "Illegal "; }
}
where $pl
is just an integer (unsigned short in C).
The script reads some data from the file.
The file contains some hex values. Those values are parsed - some bits are extracted ` and then the string representation of those bits are printed on screen.
EDIT3:
I tried to use following code:
my %table_pl = (
0 => sub { print "A"; },
1 => sub { print "B"; },
2 => sub { print "C"; },
3 => sub { print "D"; },
4 => sub { print "E"; },
);
for $pl( 0..5 )
{
if( exists $table_pl{$pl} )
{
$table_pl{$pl}->();
}
else
{
print "Illegal ";
}
}
but I got an error:
Number found where operator expected near 1
(Missing semicolon on the previous line?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我喜欢将调度表用于此类事情。从本质上讲,这是一个哈希,其中键是有效的选项,而键的值是一个子例程,在提供有效的选项时可以执行您想做的事情。这样做会消除长长的if/else语句链。
您可以将子例程内联排列在表本身中,也可以引用其他地方定义的子例程。这里的示例显示了这两个:
输出:
I like to use dispatch tables for things like this. Essentially it's a hash where the keys are the valid options, and the value of the key is a subroutine that does what you want to do when a valid option is supplied. Doing it this way eliminates a long chain of if/else statements.
You can put the subroutines inline in the table itself, or reference a subroutine defined elsewhere. The example here shows both:
Output:
缩写
可以将其写成
,但问题的全部要点是避免损坏/实验性的智能匹配功能。这将是“等效”:
它不是完全等效的。不同之处在于,最后一个对待数字
2
和字符串2
相同。智能匹配对他们的对待的事实是它是不可接受的设计的全部原因,因此这是可取的。最后,在这里,调度表可以更好地工作。通常使用哈希,但是可以将数组用于给定的示例。
调度表的优点是完成单个查找而不是多个比较。
is short for
It can be written as
But the whole point of the question is to avoid the broken/experimental smart matching feature. This would be the "equivalent":
It's not completely equivalent. The difference is that this last one treats the number
2
and the string2
identically. The fact that smart matching treats them differently is the entire reason it's an unacceptable design, so this is desirable.Finally, a dispatch table would work better here. A hash is often used, but an array could be used for the example given.
The advantage of a dispatch table is that a single lookup is done instead of multiple comparisons.