in reply to Need help with a nested IF statement
In my experience 'inet' appears on the line following the interface name, not on the same line as your example appears to assume. If this is the case, the following may be closer to what you want.
use strict; my @nic = qx |ifconfig -a| or die ("Can't get info from ifconfig: ".$! +); my $skip_to_next_if = 0; my $device; foreach (@nic){ if (/^fjgi([\d.]+)/){ # ^ +: 1 or more $device = $1; $skip_to_next_if = 0; } next if $skip_to_next_if; if (/inet ([\d.]+)/){ my $ip = $1; print "Device $device has the IP Address of $ip\n"; $skip_to_next_if = 1; } } # $ip is now out of scope...
|
|---|