M
muzzaman
I am trying to print to a socket from many parts of a program and have
therefore written a few subroutines to simplify the task. The only
issue is that it doesn't seem to pass the socket reference correctly (i
think). I get the following error:
Use of uninitialized value at line ...
which basically relates to a string ($string) I am trying to chomp
after having read it from a socket ($socket). These are the pertinent
commands:
#In main method
$socket = new IO::Socket::INET(PeerAddr => $confighost, PeerPort =>
$configport, Proto => "tcp", Type => SOCK_STREAM )or die( "Cannot
connect to $confighost:$configport : $@\n" );
$returnval = sendandreceive($socket, "Some string here");
#subroutines
sub sendandreceive {
$socket = shift;
$string = shift;
sendtosocket($socket, $string);
$returnstr = receivefromsocket($socket);
return $returnstr;
}
sub sendtosocket {
$socket = shift;
$string = subs(shift, " ", "\+");
$string = "$string\n";
print $socket $string;
}
sub receivefromsocket {
$socket = shift;
$string = <$socket>;
chomp $string;
$string = subs($string, "\+", " ");
return $string;
}
sub subs {
$string = shift;
$remove = shift;
$replace = shift;
$string =~ s/$remove/$replace/gi;
return $string;
}
Any help to (e-mail address removed) would be very much appreciated.
Regards
Muzzaman
therefore written a few subroutines to simplify the task. The only
issue is that it doesn't seem to pass the socket reference correctly (i
think). I get the following error:
Use of uninitialized value at line ...
which basically relates to a string ($string) I am trying to chomp
after having read it from a socket ($socket). These are the pertinent
commands:
#In main method
$socket = new IO::Socket::INET(PeerAddr => $confighost, PeerPort =>
$configport, Proto => "tcp", Type => SOCK_STREAM )or die( "Cannot
connect to $confighost:$configport : $@\n" );
$returnval = sendandreceive($socket, "Some string here");
#subroutines
sub sendandreceive {
$socket = shift;
$string = shift;
sendtosocket($socket, $string);
$returnstr = receivefromsocket($socket);
return $returnstr;
}
sub sendtosocket {
$socket = shift;
$string = subs(shift, " ", "\+");
$string = "$string\n";
print $socket $string;
}
sub receivefromsocket {
$socket = shift;
$string = <$socket>;
chomp $string;
$string = subs($string, "\+", " ");
return $string;
}
sub subs {
$string = shift;
$remove = shift;
$replace = shift;
$string =~ s/$remove/$replace/gi;
return $string;
}
Any help to (e-mail address removed) would be very much appreciated.
Regards
Muzzaman