in reply to One liner?
@iparray = unpack ('C4', (gethostbyname $machine) || next );
Note that || forces scalar context on gethostbyname, in which case the address is the sole return value, rendering the slice unnecessary. Take a look at perldoc -f gethostbyname, most of Perl's functions make useful distinctions between their calling contexts.
But since you're populating an array, I guess you're doing this in a loop. If this is the only thing in that loop, you might actually consider condensing this using map along these lines:
my @iparray = map defined() ? join('.', unpack 'C4', $_) : (), map scalar(gethostbyname $_), @machine;
Makeshifts last the longest.
|
|---|