Web Hosting Talk







View Full Version : perl problem


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.

Dahlia
11-04-2001, 08:33 AM
try changingmy ($host, $post, $kidpid, $handle, $line);tomy ($host, $port, $kidpid, $handle, $line);

not a perl guru, but $port isn't defined and it needs to be.. so i think you may have made a typo :o

kmb999
11-04-2001, 08:36 AM
Yes, it looks like there is a typo in your script.

node9
11-04-2001, 08:40 AM
LOL im such an idiot
sorry guys
thanks