Hi Derek

(in my last answer I wrote 'proposition' instead of 'proposal' - not native 
english speaking ;-)

Am Dienstag, 1. März 2005 23.06 schrieb [EMAIL PROTECTED]:
> Joe,
>
> if you still care, here is my final code.  Will you please eval it and them
> comment again?
>
> thanks,

(again, I didn't run the code)

> my $outfile0 = qq(/home/root/dns_servers.plout);
> open (F, "+>$outfile0") || die "could not open file: $outfile0 $!";

this way of open is ok since the filename is not an user input; 
otherwise, there is a more secure three argument form (see perldoc -f open).

> my @a=();
> my $e=0;
>         my $res = Net::DNS::Resolver->new;
>         my $query = $res->query(".ohnet", "NS");


>         if ( $query != 0 or $query != undef or $query != ' ' )  {

- This can be written shorter as "if ($query)", which means: "if query 
contains a true value"
- pay (in general) attention by combining "!=" with OR  :-)
- possible result values of method query() are: object, undef
(see man Net::DNS::Resolver)

>                 foreach ($query->answer) {
>                     if ( $_->type eq 'NS' ) {
>                     #next unless $_->type eq "A";
>                         foreach ($_->nsdname) {
>                                 push (@a,$_) if $_ =~ "svr";
>                                 $e++;
>                         } # END 2nd FOR LOOP
>         } else {
>         print F "DNS query failed: ", $res->errorstring, "\n";
>                     } # END 2nd IF
>                 } # END 1st FOR LOOP
>
>         } # END 1st IF
>         @a = sort { $a cmp $b } @a;
>         print F $a[0],"\n";
>         print F $a[1],"\n";

Maybe a dumb question (since I have no routine with Net::DNS::Resolver):
Are there alway two elements in array @a  if everything went fine?

btw: If the 1st FOR LOOP loop failed, @a is empty, so maybe you should move 
the last 3 lines in the 1st FOR LOOP  if branch.

>
> close (F);

close (F) or warn "error closing $outfile0: $!";

(not necessary her, only good style)

>
> Derek B. Smith
> OhioHealth IT
> UNIX / TSM / EDM Teams

greetings joe

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to