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

In reply to print complains about a file handle variable by SirBones

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.