node9
11-04-2001, 07:01 AM
Hey
i'm trying to get this to work
(im reading this perl book called learning perl) and im trying out a exampl ethey have for this program.
the code is below
#!/usr/bin/perl -w
use strict;
use IO::Socket;
my ($host, $post, $kidpid, $handle, $line);
unless (@ARGV == 2) {die "usage: $0 host port" }
($host, $port) = @ARGV;
# create a tcp connection to the host and port
$handle = IO::Socket::INET->new(Proto => "tcp",
PeerAddr => $host,
PeerPort => $port)
or die "cant connect on that ip and port: $!";
$handle->autoflush(1); # so output gets there right away
print STDERR "[Connected to $host:$port]\n";
#split the prog into 2 processes, identical twins
die "can't fork: $!" unless defined($kidpid = fork ());
if ($kidpid) {
while (Defined ($line = <$handle> )) {
print STOUT $line;
}
kill("TERM", $kidpid);
}
else {
while (defined ($line = <STDIN>)) {
print $handle $line;
}
}
When i run it i keep getting
linux1548:/root# perl telnet.pl
Global symbol "$port" requires explicit package name at telnet.pl line 7.
Global symbol "$port" requires explicit package name at telnet.pl line 12.
Global symbol "$port" requires explicit package name at telnet.pl line 16.
anyone know how to fix it?
im a perl newbie.
i just wanna try to get this to work.
i know some perl though.
i'm trying to get this to work
(im reading this perl book called learning perl) and im trying out a exampl ethey have for this program.
the code is below
#!/usr/bin/perl -w
use strict;
use IO::Socket;
my ($host, $post, $kidpid, $handle, $line);
unless (@ARGV == 2) {die "usage: $0 host port" }
($host, $port) = @ARGV;
# create a tcp connection to the host and port
$handle = IO::Socket::INET->new(Proto => "tcp",
PeerAddr => $host,
PeerPort => $port)
or die "cant connect on that ip and port: $!";
$handle->autoflush(1); # so output gets there right away
print STDERR "[Connected to $host:$port]\n";
#split the prog into 2 processes, identical twins
die "can't fork: $!" unless defined($kidpid = fork ());
if ($kidpid) {
while (Defined ($line = <$handle> )) {
print STOUT $line;
}
kill("TERM", $kidpid);
}
else {
while (defined ($line = <STDIN>)) {
print $handle $line;
}
}
When i run it i keep getting
linux1548:/root# perl telnet.pl
Global symbol "$port" requires explicit package name at telnet.pl line 7.
Global symbol "$port" requires explicit package name at telnet.pl line 12.
Global symbol "$port" requires explicit package name at telnet.pl line 16.
anyone know how to fix it?
im a perl newbie.
i just wanna try to get this to work.
i know some perl though.
