0

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";

1 Answer 1

1

$! 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.

Sign up to request clarification or add additional context in comments.

3 Comments

The meaning of this is equals with if($_ =~ /<P>/) ... it will work with the next line if the actual contains <P>
The whole snippet is this: if(/<P>/) {next;} chop;
So basically this code splits sentences from a given mass of text?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.