http://www.perlmonks.org?node_id=1066753


in reply to Re: Dns lookups
in thread Dns lookups

you can also get rid of that pesky array

use Socket;print "$_\n".inet_ntoa((gethostbyname$_)[4])."\n\n" for @AR +GV;

Replies are listed 'Best First'.
Re^3: Dns lookups
by hippo (Bishop) on Dec 12, 2013 at 09:44 UTC

    The array is there to cope with the possibility of an unresolvable host. If you try your example above with args like

    ./pllookup.pl dklghslfhslgshj.com foo.com

    the unresolvability of dklghslfhslgshj.com would cause it to die on the first argument, whereas with the array it will just skip that and carry on to the remaining args. To my mind that's a better UX but others may disagree.

      The golfer in me couldn't resist