You're opening and closing DATAOUT too often. How about loading an array and doing the write to file just once.

sub lookup { my ($ldns, $fqdn) = @_; my ($error, $error_a); open DIG, "$dig \@$ldns $type $fqdn | " or die $!; while (<DIG>) { if (/;; ->>HEADER<<- opcode: QUERY\s|QUERY, status: NOERRO +R, .*/) { $error = 1; next; } next unless /$fqdn\.\s+(\w+)(\s+A|\s+IN\sA)\s+(.*)/; $error_a = 1; my $time = lc($1); my $ip = $3; my $seconds = $time =~ /[dhms]/ ? string_to_time($time) : +$time; my $extended_time = time_to_string($seconds); print "Request: $fqdn\tTTL: $extended_time\tIP: $ip\n" if +$verbose; push @data_out, "$ldns\t$fqdn\t$seconds\t$ip\n" if $outfil +e; } close DIG; if (!$error) { print "Request: $fqdn\tERROR (No domain found)\n" if $verbose; push @data_out, "$ldns\t$fqdn\tERROR\tNO DOMAIN\n" if $outfile +; } elsif (!$error_a) { print "Request: $fqdn\tERROR (Domain found, no A record found) +\n" if $verbose; push @data_out, "$ldns\t$fqdn\tERROR\tNOT A RECORD\n" if $outf +ile; } }

As you can see, the code is tighter and easier to read. But, we now must add a test for @data_out.

if (@data_out) { open (DATAOUT, ">> $outfile") || die "can't open $outfile: $!"; print DATAOUT @data_out; close DATAOUT; }

This can be rewritten by taken advantage of the x operator.

foreach $thing (@ns){ push (@provide, "Unknown"); }
push @provide, ('Unknown') x @ns;

And, finally, all those ifs in the beginning could be combined.

if ( $help || !@ns && !$nsfile || !@addr && !$addrfile || !$verbose && !$outfile ) { print <<END; . . .



HTH,
Charles K. Clarkson

In reply to Re: Mass Domain Name Lookup by CharlesClarkson
in thread Mass Domain Name Lookup by argus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.