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"; } } } }

In reply to Re^2: Need help with a nested IF statement by MikeDexter
in thread Need help with a nested IF statement by MikeDexter

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.