The device name and ip are NOT on the same line.
Since you process each line one at a time, that's a problem.
The easiest solution is to look at entire records.
use strict; use warnings; my $opsys = $^O; print "Hello, your operating system is: $opsys\n"; if ($opsys =~ /linux/) { my $nics = qx|/sbin/ifconfig| or die("Can't get info from ifconfig: $!\n"); my @nics = split /(?<=\n)(?=\w)/, $nics; for (@nics){ my ($device) = /^eth(\d)/ or next; my ($ip) = /\bnet addr:([\d.]+)/ or next; print "Device $device has the IP Address of $ip\n"; } } else { my $nics = qx|ifconfig -a| or die("Can't get info from ifconfig: $!\n"); my @nics = split /(?<=\n)(?=\w)/, $nics; for (@nics){ my ($device) = /^fjgi(\d)/ or next; my ($ip) = /\binet ([\d.]+)/ or next; print "Device $device has the IP Address of $ip\n"; } }
There's some redundancy here, but I can't figure how to eliminate cleanly.
In reply to Re^3: Need help with a nested IF statement
by ikegami
in thread Need help with a nested IF statement
by MikeDexter
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |