in reply to Can I condense the variable usage here?

The test: ($MachineName eq "") is never going to be true, because of the or in the initialization of it. That means that you are only using $MachineName once, and can probably just inline it. This ought to be equivalent to your code:
if ($pingObj->ping($IpAddress, 1)){ my $MachineName = uc(gethostbyaddr (inet_aton($IpAddress), AF_INET) +) or "[FAILED]"; $MachineName = ($MachineName =~ /^(.*?)(-UDP\w*)?\./i)[0]; print "$IpAddress\t$MachineName" if $VERBOSE; } else { print "$IpAddress\tNo Response\n" if $VERBOSE; }
But you probably meant ($Host eq ''), didn't you? That would be a good thing to check, if the match, er, didn't. Easy enough:
# Assuming you won't have a machine named "0" $MachineName = ($MachineName =~ /^(.*?)(-UDP\w*)?\./i)[0] || ($IpAd +dress . '[NULL]');

The PerlMonk tr/// Advocate

Replies are listed 'Best First'.
Re: Re: Can I condense the variable usage here?
by Ninthwave (Chaplain) on Dec 23, 2003 at 20:53 UTC

    Oddly enough the code supplies catches .company.com look ups we found. I was getting blank input and caught it with that. I am sure I meant $Host eq '' but the code I cut and paste worked. Though it may have been off the edit version I was working on to change the regex. When I get back to work I will look at the in production code versus the new version I was working on. I believe we tried a regex like you supplied but the problem is their is a value in the string with a value of .company.com but after the regex that is reduced to '' and it was a catch at the bottom.

    Besides catching this in the script I need to know than how to fix these machines that have a null computer name, but that is another query for another place.

    "No matter where you go, there you are." BB