When I played like this it was writing a SMTP and POP module (just cause it was a good exercise)..

# # initialization # $self->{'sock'} = IO::Socket::INET->new( args => 'go_here', ) || die "Cant create socket\nReason: $!\n"; # #retrieval for use # $sock = $obj->_get_sock(); sub _get_sock { return($_[0]->{'sock'}); }
I honestly shouldn't be playing like that, cause I'm not quite sure how it works, only simply that it does. So I am assuming you could do something similar by storing it in a hash or even in an array and passing the hash/array around and then pulling the reference to the socket back out of the data structure.

Hopefully someone more wizardly will explain what is going on. I believe that the IO::Socket returns a object, which is really just a blessed reference to a data structure. So you should be able to say.
$sock = IO::Socket::INET->new( args => 'go_here', ) || die "blah\n$!\n"; $sock_ref = \$sock; some_func($sock_ref); sub some_func { $ref = shift; $sock = ${$ref}; $line = <$sock>; }
Edit: I should clarify a little I guess, I do know how the code works, and what I am passing around, and even what is going on in _get_sock, Im just not overly familiar with OOP. I use it, but I don't understand all of the inner workings of perl OOP, and there are better ways to play with sockets. It was simply a shotgun approach, which proved I could prototype what I wanted and get a working model. I probably should have read your code, as opposed to simply assuming you wanted to know how to pass a socket around.

/* And the Creator, against his better judgement, wrote man.c */

In reply to Re: Passing IO::Socket::INET by l2kashe
in thread Passing IO::Socket::INET by jk2addict

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.