in reply to Need help with a nested IF statement
Why are you printing the IP address when you have haven't found one (i.e. when the inner if hasn't been entered)? Don'thide errors. Please use use strict; use warnings;!
use strict; use warnings; 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"; } } }
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
Are you sure there's a line that both starts with fjgi and contains inet? I'm not familiar with the output of ifconfig, but I suspect that isn't the case.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Need help with a nested IF statement
by MikeDexter (Sexton) on Nov 02, 2009 at 17:09 UTC | |
by ikegami (Patriarch) on Nov 02, 2009 at 17:21 UTC | |
|
Re^2: Need help with a nested IF statement
by MikeDexter (Sexton) on Nov 02, 2009 at 17:15 UTC | |
by ikegami (Patriarch) on Nov 02, 2009 at 17:38 UTC | |
by MikeDexter (Sexton) on Nov 02, 2009 at 18:16 UTC | |
by ikegami (Patriarch) on Nov 02, 2009 at 18:36 UTC | |
by MikeDexter (Sexton) on Nov 02, 2009 at 20:24 UTC | |
by ikegami (Patriarch) on Nov 02, 2009 at 20:30 UTC | |
by MikeDexter (Sexton) on Nov 03, 2009 at 13:42 UTC | |
|