gpt4 book ai didi

perl - Perl 中的 "Use of uninitialized value in scalar chomp"

转载 作者:行者123 更新时间:2023-12-04 18:15:31 39 4
gpt4 key购买 nike

运行脚本时出现以下错误:有人可以帮我解决这个问题吗

Use of uninitialized value $user in scalar chomp at ./temp.pl line 38, <DATA> line 558.
Use of uninitialized value $modelName in scalar chomp at ./temp.pl line 39, <DATA> line 558.
Use of uninitialized value $Application in scalar chomp at ./temp.pl line 40, <DATA> line 558.
Use of uninitialized value $user in string eq at ./temp.pl line 42, <DATA> line 558.

代码如下,有人可以帮助我吗:
my ($user) = $ARGV[0];
my ($modelName) = $ARGV[1];
my ($Application) = $ARGV[2];

chomp($user);
chomp($modelName);
chomp($Application);

if ( ($user eq "") || ($modelName eq "") || ($Application eq "")) {
&usage;
}

sub usage {
print "\tUsage : $0 User ModelName Application\n";
exit (1);
}

最佳答案

该程序在命令行上需要参数 - 用户、模型名称和应用程序,而您没有提供

无需chomp从命令行传递的值,因为它永远不会以新行结尾

你的代码最好这样写

usage() unless @ARGV == 3;

my ($user, $modelName, $Application) = @ARGV;

关于perl - Perl 中的 "Use of uninitialized value in scalar chomp",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11822049/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com