in reply to Can I condense the variable usage here?

A few thoughts other than variables.
  1. Generally, I like to deal with my error conditions before dealing with my success conditions. Something like:
    sub getHostname { my ($IpAddress) = @_; unless ($pingObj->ping($IpAddress, 1)) { print "No response from $IpAddress\n" if $VERBOSE; return; } # Do the rest of the stuff here }
  2. As for your variables, maybe something like:
    # This is the rest of the stuff. # Note the use of single quotes. It's not a performance thing - it +'s a # readability thing. Double-quotes are for interpolation. Single-q +uotes # tell the reader there's no interpolation here. my $Host = uc(gethostbyaddr (inet_aton($IpAddress), AF_INET)) or '[FAILED]'; # Get rid of everything starting with -UDP. # In your version, you captured everything before -UDP. Same diffe +rence. $Host =~ s/-UDP.*//; $Host = "${IpAddress}[NULL]" if $Host eq ''; print "$IpAddress\t$Host\n" if $VERBOSE; return $Host; }
  3. As for threading issues, I'm definitely not the one to ask about that. You'll probably have to add lock() somewheres.

------
We are the carpenters and bricklayers of the Information Age.

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

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

    It works fine in threads I am just trying to have less variables, so that overall I am carrying less baggage in the threads.

    Though I must agree I like unless more than if, but after so many years using if exlusively I don't intially think of using unless. This is a thought process I must try to change.

    The regex change is much better thank you. It goes to show when you put code together to get it to work, that bits can grow and you should learn to trust the gut instinct that you need to revisit a section again. This bit of code intially just got the host name but over the time of looking at the output we added more to it. And I kept feeling it needed a revisit. But when I would look at it I saw how it worked and why we did it that way and couldn't think out of the box we built.

    Thank you again.

    Update:
    I modified the regex in my code for to look like this:

    $Host =~ s/(-UDP.*|\..*)//;

    Which seems to be testing fine but still need to throw it some weird machine names to be sure.

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