Ninthwave has asked for the wisdom of the Perl Monks concerning the following question:
I have working code for trimming off some of the names we get returned from DNS to leave just the computer name. I have to drop it through two variables and I have a gut feeling I could be doing this in one step instaed of two. This code works but are there any suggestions to simplify this code:
if ($pingObj->ping($IpAddress, 1)){ my $MachineName = uc(gethostbyaddr (inet_aton($IpAddress), + AF_INET)) or "[FAILED]"; my $Host = ($MachineName =~ /^(.*?)(-UDP\w*\.|\.)(.*)/i)[0 +]; $Host = "$IpAddress" . "[NULL]" if ($MachineName eq ""); print "$IpAddress\t$Host" if $VERBOSE; } else { print "$IpAddress\tNo Response\n" if $VERBOSE; } }
To simplify my query what are the other ways the monks would write the above code?
Update:
Corrected typo perfomr to perform
Changed "Note this section of the code is most likely going to be in an thread." updated version above. I feel this more accurately reflects the state of the code example.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Can I condense the variable usage here?
by dragonchild (Archbishop) on Dec 23, 2003 at 13:02 UTC | |
by Ninthwave (Chaplain) on Dec 23, 2003 at 13:57 UTC | |
|
Re: Can I condense the variable usage here?
by jeffa (Bishop) on Dec 23, 2003 at 14:33 UTC | |
by Ninthwave (Chaplain) on Dec 23, 2003 at 16:09 UTC | |
|
Re: Can I condense the variable usage here?
by Roy Johnson (Monsignor) on Dec 23, 2003 at 18:20 UTC | |
by Ninthwave (Chaplain) on Dec 23, 2003 at 20:53 UTC |