http://www.perlmonks.org?node_id=578341

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

I've started playing with Perl objects. I've got a nice little class that establishes a TCP/IP socket and supports some communications functions along that socket. The hash key for the socket name is 'S', which was created and assigned in my constructor, and which is referred to in my methods as $me->{S}, i.e.:

sub readSocket { my $me = shift; . . my $readNum = read($me->{S}, $inData, 4); . }

This works fine.

But if I try to use it here:

sub socketSend { my $me = shift; . . . my $outData; . . # <Do stuff that builds $outData> . . print $me->{S} $outData; }

I get this error:

Scalar found where operator expected at PTComm.pm line 205, near " +} $outData" (Missing operator before $outData?) syntax error at PTComm.pm line 205, near "} $outData"

But if I do this:

my $h = $me->{S}; print $h $outData;

All is well.

I'm sure someone will tell me in short order: What gives? (Please.)

(Thanks, as usual.)

-Ken

"This bounty hunter is my kind of scum: Fearless and inventive." --J.T. Hutt