in reply to Problem parsing Apache configuration

A couple of quick comments:

Here is a bit of working (tested) code that emulates what you are trying to do (except for poulating the hash), and does hostname lookups using gethostbyaddr. Perhaps this will help:

#!/usr/bin/perl -w use strict; use Socket; while (<DATA>) { if (/^Listen/) { chomp; my ($ip) = $_ =~ m/^Listen\s([\d\.]+):?/; my $host = gethostname($ip) || "unknown"; print "IP:$ip HOST:$host\n"; } } sub gethostname { my $ip = shift; my $iaddr = inet_aton($ip); return gethostbyaddr($iaddr, AF_INET); } __DATA__ Listen 1.2.3.4 Listen 5.6.7.8:9735 rubbish Listen 209.131.36.158 Listen 11.12.1.4:8080 more rubbish
Output:
IP:1.2.3.4 HOST:unknown IP:5.6.7.8 HOST:unknown IP:209.131.36.158 HOST:f1.www.vip.sp1.yahoo.com IP:11.12.1.4 HOST:unknown

To check the contents of your hash, you might consider using Data::Dumper.

Cheers,
Darren