If your code is more structured, it will be easier for other people to understand your code, and more monks will join to debug for you. More importantly, easier for yourself to debug.

Compare your code with the following rewrite (I am just trying to show a better structure, not doing everything), don't you think the rewrite is much easier to understand and debug?Maybe you can start from here.

use IO::Socket::INET; use IO::Select; use strict; use warnings; my $socket = new IO::Socket::INET(Proto => "udp"); my $select = new IO::Select($socket); my $num_packet_rcvd; my $packet_rcvd; for (4000 .. 4100) {#change this to your logic of going thru peer list my $peer = sockaddr_in($_, inet_aton("localhost")); $socket->send("1234567890", 0, $peer) || die "send: $!";#instead o +f die, your real code shall handle it, for example logging print "packet sent to port $_\n"; } while (1) { my @sockets = $select->can_read(10); last if ($#sockets == -1);#no more reply within a reasonable amoun +t fo time $num_packet_rcvd ++; $socket->recv($packet_rcvd, 100); print "rcvd packet $num_packet_rcvd [$packet_rcvd]\n";#you will re +place this with your stuff }

In reply to Re: Problems with select() on socket by pg
in thread Problems with select() on socket by Anonymous Monk

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.