in reply to Can I condense the variable usage here?
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 }
# 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; }
------
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 |