加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

关于评论和原型的这两个警告在Perl中是什么意思?

发布时间:2020-12-15 21:59:59 所属栏目:大数据 来源:网络整理
导读:我有以下代码 #! /usr/bin/perluse strict;use warnings;################### Start Main ####################my @startupPrograms = qw(google-chrome thunderbird skype pidgin );my @pagesToBeOpenedInChrome = qw(http://www.google.com/ https://stack
我有以下代码
#! /usr/bin/perl

use strict;
use warnings;

################### Start Main ####################
my @startupPrograms = qw(google-chrome thunderbird skype pidgin );
my @pagesToBeOpenedInChrome = qw(http://www.google.com/ https://stackoverflow.com/ https://mail.google.com/mail/u/0/#inbox);
main();


#################################################

sub main() {

}

我得到以下警告

[aniket@localhost TestCodes]$./test.pl 
Possible attempt to put comments in qw() list at ./test.pl line 8.
main::main() called too early to check prototype at ./test.pl line 9.

程序工作正常,但我无法理解警告.他们的意思是什么?

解决方法

这个警告:
Possible attempt to put comments in qw() list at ./test.pl line 8.

指指定行的这一部分:

.... https://mail.google.com/mail/u/0/#inbox);
                                 # ---^

#号是Perl中的一个注释,qw()附有一些特殊警告.这不用担心,但在这种情况下它看起来像一个冗余的警告.如果你想修复它,你可以把这个作业放在一个块中,不要使用’qw’的警告.然而,这与词法范围的变量有些笨重:

my @pages;    # must be outside block
{
    no warnings 'qw';
    @pages = qw( .... );
}

我对警告“qw”的有用性有些疑问,而在一个小脚本中,您可以通过在脚本的顶部添加任何警告“qw”来全局删除编译指示.

这个警告:

main::main() called too early to check prototype at ./test.pl line 9.

这与您的子名称后面的空括号有关.它们表示您希望使用prototypes与您的子例程,并且您的子应该被调用没有args.原型用于使子程序表现得像内置函数,这就是说它不是你真正需要担心的事情,几乎在所有情况下都应该忽略.所以只需删除空的括号.

如果你真的希望使用原型,你需要将一个预声明或者子声明本身放在你打算使用的地方之前.例如.

sub main ();  # predeclaration

main();

sub main () {
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读