I am writing a Perl script that will run on Solaris an "ifconfig" then will print out the name of the device and the ip address for that device. I have two IF statements that work on their own but when I place them both into my foreach loop, the second IF gets skipped over. I entered a print "test" line to debug and the word test never appears in the output. I have these in the same foreach so that they align the IP address and device together.
My expected output would be "Device 0 has an ip address of xxx.xxx.xxx.xxx newline Device 1 has an ip address of xxx.xxx.xxx.xxx newline exit-loop.
$ifconfig = "ifconfig -a"; @nic = qx |$ifconfig| or die ("Can't get info from ifconfig: ".$!); foreach (@nic){ if (/^fjgi([\d.])/){ $device = $1; if (/inet ([\d.]+)/){ print "test $1\n"; $ip = $1; } print "Device $device has the IP Address of $ip\n"; } }
In reply to Need help with a nested IF statement by MikeDexter
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |