I found this module on the internet that deals with communicating over the internet and I'd like to mess with the code to change some things but I don't really understand the code which is based around the procedural form of Socket. So I my question is can anyone either translate this or just give me some translating tips as to how to go from Socket to IO::Socket?
sub q3msg { my ($host, $port, $timeout, $msg) = @_; my $iaddr = gethostbyname(hostname()); my $sin = sockaddr_in(0, $iaddr); socket(SOCK, PF_INET, SOCK_DGRAM, getprotobyname('udp')) or die "s +ocket: $!\n"; bind(SOCK, $sin) or die "bind: $!\n"; my $hisaddr = inet_aton($host) or die "unknown host \"$host\"\n"; my $srvaddr = sockaddr_in($port, $hisaddr); defined(send(SOCK, chr(255) x 4 . $msg, 0, $srvaddr)) or die "send +: $!\n"; my ($rin, $rout); $rin = ""; vec($rin, fileno(SOCK), 1) = 1; if (select($rout=$rin, undef, undef, $timeout)) { recv(SOCK, $_, 65507, 0) or die "recv: $!\n"; s/\033.//g; my @response = split /^/m; shift @response; return \@response; } else { return undef; } }


Update
To expand a little, the main change I was trying to do was try to avoid having to create a socket everytime, as currently when I use it its a tad slow (2-3 seconds to send/receive a response) and I was trying to optimize that, my first thought was to just create one socket that could stay in existance and hopefully make it a bit faster.

In reply to Translating Socket to IO::Socket; by BUU

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.