himanh has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am back with some updated script on the Whois script. I did manage to create a script which reads each line from a text file and then dumps the nameserver of each domain in another file. It ran good for a file that has 3-4 domains but when i added all the domains(may be 40-50) it started crashing. I try to fix but i think i broke the whole thing. Here is the code for the existing script that does not run. Any suggestions ?
#!/usr/bin/perl use warnings; use CGI::Carp qw/fatalsToBrowser/; use Net::DNS; my $res = Net::DNS::Resolver->new; my $logTime = gmtime(time); open(fileIN,"domains.txt") or dienice("Cannot open domains list: $!"); @logData = <fileIN>; close(fileIN); print header("text/plain"); print "Header :: $logTime \n"; foreach $line(@logData) { chomp($line); my $dom = $line ; my $query = $res->query($dom, "NS"); if ($query) { open(fileOUT, ">>log.txt") or dienice("Can't open log.txt for writing: + $!"); flock(fileOUT, 2); seek(fileOUT, 0, 2); print fileOUT "$dom : "; print "$dom : "; foreach $rr (grep { $_->type eq 'NS' } $query->answer) { print fileOUT $rr->nsdname, ","; print $rr->nsdname, ","; } } print "\n",<br>; print ".",<br>; print <<EndHTML; Added domain : $dom <br> EndHTML } close (fileOUT); sub dienice { my($msg) = @_; print "<html>\n<head>\n<title>Error Opening File!</title>\n"; print "</head>\n"; print "<body><h2>Error</h2>\n<b>"; print $msg; print "\n</b></body>\n</html>"; exit; }

Replies are listed 'Best First'.
Re: Problem in the new DNS script
by BUU (Prior) on Jan 12, 2005 at 19:11 UTC
    Just taking a random guess since you haven't told us *how* it's not working, you don't appear to have defined the subroutine "header" and none of the modules you use export it, so perhaps thats the error.
      Thanks BUU, I think you are pointing to right direction. I had a problem before with the headers so i got this line from somewhere since someone replied saying that my header is not getting set. I also had one line something like  print "Content text/plain \n \n"; But i think it did not work. Can you tell me if there is something wrong with the script ? I am getting internal server error. Thanks.
      A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Problem in the new DNS script
by davido (Cardinal) on Jan 13, 2005 at 08:30 UTC

    header() looks a lot like a method (or exported sub) found in the CGI.pm module. And the fact that you're using CGI::Carp does somewhat lend support for the notion that this is a CGI script. So if you're going to use the CGI module's subroutines, you should probably "use CGI qw/:standard/;"

    While you're at it, be sure to read the POD for CGI.


    Dave