Reputation: 1603
I am working on an open source project for GSoC and I have this piece of Perl code with me. I need to create another Perl file for a similar task. However, I am having trouble understanding 3 lines of this file. 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";
Upvotes: 0
Views: 126
Reputation: 69505
$! 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. 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.
Upvotes: 1