in reply to Re: Need help with a nested IF statement
in thread Need help with a nested IF statement

Hi there. I tried changing my IF's to resemble your example but when I run the script I don't get any output. This script from the top will first identify the operating system and then dump into the appropriate loop per the os it finds. For Solaris, $opsys is not true for linux so we jump to the else statement. There is the code as per your suggestion. When I run the script on Solaris is says I am on Solaris but no other data is printed at all.

Would you mind taking another look to see if I missed something?

use strict; use warnings; my($opsys) = "$^O"; print "Hello, your operating system is: $opsys" . "\n"; if ($opsys =~ /linux/) { my $ifconfig = "/sbin/ifconfig"; my @nic = qx |$ifconfig| or die ("Can't get info from ifconfig: $!\ +n"); for(@nic){ if (my ($device) = /eth(\d)/){ if (my ($ip) = /net addr:([\d.]+)/){ print "Device $device has the IP Address of $ip\n"; } } } } else { my $ifconfig = "ifconfig -a"; my @nic = qx |$ifconfig| or die ("Can't get info from ifconfig: $!\ +n"); for (@nic){ if (my ($device) = /^fjgi(\d)/){ if (my ($ip) = /inet ([\d.]+)/){ print "Device $device has the IP Address of $ip\n"; } } } }

Replies are listed 'Best First'.
Re^3: Need help with a nested IF statement
by ikegami (Patriarch) on Nov 02, 2009 at 17:21 UTC

    I tried changing my IF's to resemble your example but when I run the script I don't get any output.

    Of course. You haven't fixed the problem of the inner "if" not matching

    Would you mind taking another look to see if I missed something?

    You seem to have missed the question in my earlier post. ( I see you addressed that in a separate post. Replying to that post now )