js1 has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I have a problem with my code. I'm writing a program to parse a list of apache config files, and print out all the Listen directives e.g. Listen 1.2.3.4, followed by the corresponding hostname.
This is my hash to store the information it parses:
if(/\s*Listen\s+(\S*)/){ $instdetails{$instnum}{Listen}{$1}=1; $instdetails{$instnum}{Listen}{$1}{host}=gethost($1); next; }
However when it comes to printing out the hash, the hostname is the same on each line, eventhough the ip address changes. e.g.
1.2.3.4 www.test.com
5.6.7.8 www.test.com
4.3.2.1 www.test.com
etc.
This is the code I'm using:
printf "\n%-20s","Listen:"; $hashref=$instdetails{$instnum}{Listen}; foreach $listen(keys %$hashref){ $host=$instdetails{$instnum}{Listen}{$listen}{host}; printf "\n%-20s$listen ($host)",""; }
Can anyone see my mistake?
Thanks,
js1.
2006-08-16 Retitled by holli, as per Monastery guidelines
Original title: 'problem in code'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem parsing Apache configuration
by McDarren (Abbot) on Aug 16, 2006 at 12:25 UTC | |
|
Re: Problem parsing Apache configuration
by friedo (Prior) on Aug 16, 2006 at 12:31 UTC | |
|
Re: Problem parsing Apache configuration
by bangers (Pilgrim) on Aug 16, 2006 at 12:12 UTC | |
|
Re: problem in code
by js1 (Monk) on Aug 16, 2006 at 12:47 UTC | |
|
Re: Problem parsing Apache configuration
by js1 (Monk) on Aug 16, 2006 at 12:56 UTC |