On Thu, Jan 1, 2009 at 07:38, Duck <charles.kendri...@charter.net> wrote:
> I am writing a script to ping several systems and then to run nslookup
> on those that fail the ping test.  How do I capture the exit status of
> the system commands.  I tried something like:
>
> $status = system("nslookup xxx.xxx.xxx.xxx");
> print "$status";
>
> but this seems to print "0" every time whether the nslookup found the
> IP address or not.
snip

Whenever you find yourself reaching for the system function, stop and
search CPAN* first.  There is usually a module that does what you want
already.  In this case, you should probably be using Net::Ping** and
Net::Nslookup***.  Using modules is usually more efficient. more
reliable, and easier than executing an external command and parsing
its output.

* http://search.cpan.org
** http://search.cpan.org/dist/Net-Ping/lib/Net/Ping.pm
*** http://search.cpan.org/dist/Net-Nslookup/lib/Net/Nslookup.pm


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to