The value of the internal file handle should suffice. To give some background, I am writing a simple mock tcp server, using IO::Socket::INET and IO::Select, to use in system testing. It is not finished yet, but as a minimum I'd like to at least display the socket ids in a trace so I can tell which client is sending what. Here are some (incomplete) code snippets to give you a feel:

my $listener = IO::Socket::INET->new( LocalPort => $port, Proto => 'tcp', Listen => 5, ReuseAddr => 1, ) or die "error: IO::Socket::INET: $@"; my $selector = IO::Select->new($listener); while ( my @ready = $selector->can_read() ) { for my $client (@ready) { if ( $client == $listener ) { my $new_conn = $listener->accept(); $selector->add($new_conn); my $fh_hex = sprintf '0x%x', $new_conn; print "Accepted new connection ($fh_hex)\n"; # ... sub recv_client { my $client = shift; my $fh_hex = sprintf '0x%x', $client; print "Recv from client ($fh_hex):\n"; # ... display data received ... }

Update: Thanks to BrowserUk's excellent tip I am now using:

my $fh_hex = sprintf '0x%x', $new_conn; my $peerhost = $new_conn->peerhost(); my $peerport = $new_conn->peerport(); my $peeraddr = $new_conn->peeraddr(); my $peerhostfull = gethostbyaddr($peeraddr, AF_INET) || "Cannot resolv +e"; print "Accepted new connection $fh_hex ($peerhost:$peerport,host=$peer +hostfull)\n";
which is much better.


In reply to Re^2: Hex value of Perl file handle to uniquely identify by eyepopslikeamosquito
in thread Hex value of Perl file handle to uniquely identify by eyepopslikeamosquito

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.