[英]Command line arguments in Perl
I am working on an open source project for GSoC and I have this piece of Perl code with me. 我正在为GSoC开发一个开源项目,并且我已经拥有了这段Perl代码。 I need to create another Perl file for a similar task.
我需要为类似的任务创建另一个Perl文件。 However, I am having trouble understanding 3 lines of this file.
但是,我在理解此文件的3行时遇到了麻烦。 More specifically, I am not able to understand why the files have
$
symbol. 更具体地说,我无法理解为什么文件带有
$
符号。 I assume it is because they are command line arguments. 我认为这是因为它们是命令行参数。 However, I am not sure.
但是,我不确定。 I would like to have the meaning of these 3 lines explained to me.
我想向我解释这三行的含义。
open(NC, "|nc localhost 17001") || die "nc failed: $!\n";
print NC "scm hush\n(observe-text \"$_\")\n";
print "submit-one: $_\n";
$! $! and $_ are global variables.
和$ _是全局变量。 For more information you can read here
欲了解更多信息,请点击这里
$_ The default input and pattern-searching space
$ _默认输入和模式搜索空间
$!
$! If used in a numeric context, yields the current value of the errno variable, identifying the last system call error.
如果在数字上下文中使用,将产生errno变量的当前值,标识出最后一个系统调用错误。 If used in a string context, yields the corresponding system error string.
如果在字符串上下文中使用,则产生相应的系统错误字符串。
open(NC, "|nc localhost 17001") || die "nc failed: $!\n";
will run the command nc with the parameter and if it fails it will give you the error message. 将使用参数运行nc命令,如果失败,则会显示错误消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.