I am using the following code to read in a web site access log file and translate IP addresses to their domain names:
1 open(LOG, "$logfile");
2 open(TEMP, ">$tempfile");
3 while(my $line = <LOG>)
4 {
5 if($line =~ /^(\d{2,}\.\d{2,}\.\d{2,}\.\d{2,})/)
6 {
7 my $ip_address = $1;
8 unless (exists $hostname{$ip_address})
9 {
10 $hostname{$ip_address} = gethostbyaddr
(inet_aton($ip_address), AF_INET);
11 print TEMP "$ip_address -> $hostname{$ip_address}\n";
12 }
13 }
14 }
15 close TEMP;
16 close LOG;
Here is my question: Line 10 can take a long time to process just one IP address to domain name lookup. How can I use alarm to set a timeout after 1 second has passed?
Thank you very much for any help.
1 open(LOG, "$logfile");
2 open(TEMP, ">$tempfile");
3 while(my $line = <LOG>)
4 {
5 if($line =~ /^(\d{2,}\.\d{2,}\.\d{2,}\.\d{2,})/)
6 {
7 my $ip_address = $1;
8 unless (exists $hostname{$ip_address})
9 {
10 $hostname{$ip_address} = gethostbyaddr
(inet_aton($ip_address), AF_INET);
11 print TEMP "$ip_address -> $hostname{$ip_address}\n";
12 }
13 }
14 }
15 close TEMP;
16 close LOG;
Here is my question: Line 10 can take a long time to process just one IP address to domain name lookup. How can I use alarm to set a timeout after 1 second has passed?
Thank you very much for any help.