Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Push to Reference

by VinsWorldcom (Parson)
on Oct 10, 2017 at 11:07 UTC ( #1201096=note: print w/replies, xml ) Need Help??


in reply to Push to Reference

Looks like haukex may have solved your problem above, so just an observation:

  • It's 2017, we really should be using address family independent Socket routines.

Unless you're *guaranteed* that:

  • @ips will only be IPv4 addresses, or
  • you're on a Perl older than 5.14, or
  • your Socket module version is older than 1.94, or
  • you're using an operating system circa Windows XP ...

you may encounter IPv6. So planning for it is easy:

#!perl use strict; use warnings; my @bla = qw ( 34.230.53.172 2607:f8b0:400d:c0b::63 ); for my $bla (@bla) { ### What you need below ### use Socket qw( AF_INET IPPROTO_TCP ); my $AF_UNSPEC = eval { Socket::AF_UNSPEC() }; my $NI_NAMEREQD = eval { Socket::NI_NAMEREQD() }; my %hints = ( family => $AF_UNSPEC, protocol => IPPROTO_TCP ); my ( $err, @getaddr ) = Socket::getaddrinfo( $bla, undef, \%hints ); for my $addr (@getaddr) { my ( $err, $host, $service ) = Socket::getnameinfo( $addr->{addr}, $NI_NAMEREQD ); printf "%s\n", ( defined($host) ) ? $host : $err; } ### What you need above ### }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1201096]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2018-11-17 11:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (202 votes). Check out past polls.

    Notices?