Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm trying to use Socket as object's local data....

I'm doing this on init :
$self->{LMCE_command_sender} = IO::Socket::INET->new(PeerAddr => $ +self->{host_url}, PeerPort => $self->{port} , Proto => 'tcp') or die +"\nCould not create socket: $!\n";

and then I can do this :
Send_Message_To_LMCE($self,$self->{LMCE_command_sender},"EVENT $device +_ID");

but this doesn't work :
Send_Command_To_LMCE ($self,"EVENT $device_ID");

and I have :
# send generic message to LMCE socket $sockett sub Send_Message_To_LMCE { my ($self,$sockett,$message) = @_; $message = $message . "\r\n"; print $sockett $message; print "Sending Generic Message to LMCE DCE : $message\n"; } # send command to LMCE Command socket sub Send_Command_To_LMCE { my ($self,$message) = @_; $message = $message . "\r\n"; print $self->{LMCE_command_sender}, $message; print "Sending Command Message to LMCE DCE : $message\n"; }

I had to put comma in print line in Send_Command_To_LMCE (not sure why). What am I doing wrong? It seems that $self->{LMCE_command_sender} is not properly recognized as socket interface...

Thanks in advance,

Bulek.

Replies are listed 'Best First'.
Re: Having TCP Socket as object 's data
by Fletch (Bishop) on Nov 29, 2007 at 00:14 UTC

    The only thing allowed in the filehandle / indirect object "slot" for print is either a bareword handle name or a simple scalar variable $foo. Anything more complex (such as an element of a hashref in this case) needs to be given as a BLOCK: print { $self->{socket} } "rest", "of", "arguments";.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.