ChrisR has asked for the wisdom of the Perl Monks concerning the following question:
I was able to get it down to this:($name,$aliases,$addrtype,$length,@addrs) = gethostbyname($machine +); if($#addrs == -1){ next; } $ipadrs = join ".", unpack('C4', $addrs[0]); @iparray = split(/\./,$ipadrs);
As close as I have gotten to a one liner is:@addrs = gethostbyname($machine) or next; @iparray = unpack('C4', $addrs[4]);
In the above line, if the gethostbyname() function fails because the machine is not available, a warning of uninitialized value is thrown since the array being fed to unpack was never created. I was't able to get it to work using the or next; idea. I'm sure there is a way to do it, I just haven't found it. Possibly a code reference or eval though I don't know much about those. Any tip in the right direction will be greatly appreciated.@iparray = unpack ('C4',((gethostbyname($machine))[4]));
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: One liner?
by jonadab (Parson) on Oct 01, 2003 at 01:11 UTC | |
by ChrisR (Hermit) on Oct 01, 2003 at 01:52 UTC | |
by jonadab (Parson) on Oct 01, 2003 at 02:54 UTC | |
|
Re: One liner?
by Aristotle (Chancellor) on Oct 01, 2003 at 09:30 UTC |