use*_*037 2 perl die line-numbers
我想写点:
die "Error in file $0 line number $line_number_of_this_cmd_in_file \n";
Run Code Online (Sandbox Code Playgroud)
在我的perl脚本文件中.
有帮助吗?多谢!
(perl 5)
如果你没有把\n放在你传递给die的字符串的末尾,那么perl会自动添加行号.
否则,令牌__LINE__将为您提供脚本中的当前行号(并__FILE__提供当前文件名).
除非你的意思是你刚读取的文件的当前行号 - 可以在$中找到.
这很简单:删除\n行的末尾,die并附上您用脚本名称和行号写的任何消息.例如:
die "Encountered error 15 ";
Run Code Online (Sandbox Code Playgroud)
将导致它打印:
"Encountered error 15 at script.pl line 42\n"
Run Code Online (Sandbox Code Playgroud)
或任何适用的.