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'
In reply to Problem parsing Apache configuration by js1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |