in reply to Re^2: parsing a terrible /etc/hosts
in thread parsing a terrible /etc/hosts

Config::Hosts Interface to /etc/hosts file

if ($hosts->{$ip}) { print STDERR "Line $l: Warning: duplicate IP entry $ip, the last one + will be used\n"; }
As far as i remember(AIX, ubuntu, win) you may have duplicate lines with the same ip and they are "joined".

Also "output" mixes up names and ips in same array. While strange, this is a valid line
127.0.0.1 192.168.0.1
it makes the host-name 192.168.0.1 map to the ip of 127.0.0.1, common use is by script kiddies tho.

Parse::Hosts Parse /etc/hosts

unless (defined $content) { open my($fh), "<", "/etc/hosts" or return [500, "Can't read /etc/hosts: $!"]; local $/; $content = <$fh>; }
only reads /etc/hosts or you have to read it yourself and pass it in. "output" is an array of hashs {ip => $ip, hosts => \@hosts}

App::ParseHosts Parse /etc/hosts (CLI) Just a wrapper around Parse::Hosts to allow you to read anyfile

Mine parses the lines same way as them, and has more usable data structures for the task and example. Mine doesnt check for valid ipv4 or ipv6 format tho like Config::Hosts almost does. I looked at Config::Hosts first and didnt like it

add: and none are core either