stevieb's approach is probably the way to go, however it assumes that if BR_IP = "n" then you go and search CoreVlanIP for matches. In the code below I assume that if BR_IP = "n" then do nothing, but if the @brnwlist is empty then search CoreVlanIP for matches. I have added some print statements and use Data::Dumper to show what is going on (a habit worth acquiring):
use Data::Dumper; my $count = 1; foreach my $server (@{$servers->{server}}) { print "\nCount: ", $count++, "\n"; my $brlan = $server->{BRLAN} ; print "brlan = $brlan\n"; next unless $brlan eq "y"; my $brip = $server->{BR_IP}; my $num = $server->{CoreLanNum}; my $corebrip = $server->{'CoreLanIP_'.$num.'__1'} ; my $brmask = $server->{'CoreLanNetmask_'.$num}; my @brnwlist; for my $n (1..$num){ $corebrip = $server->{'CoreLanIP_'.$n.'__1'} ; if (not $corebrip) { print "CoreLanNum $n - No value for CoreLanIP_".$n."__1\n" +; next; } print "CoreLanNum $n - brip: $brip, corebrip: $corebrip\n"; $brmask = $server->{'CoreLanNetmask_'.$n}; if ( $corebrip eq $brip ){ my $brlist = join ("/", $brip, $brmask) ; $brlist =~ s/.[0-9]*\//.0\//g; push( @brnwlist, $brlist) unless $seen{$brlist}++; } else { print "coreip does not match brip\n"; } } print "brnwlist: ", Dumper(\@brnwlist); next if @brnwlist; my @vnwlist; my $vnum = $server->{CoreVlanNum}; for my $i (1..$vnum){ my $vlanip = $server->{'CoreVlan_IP_'.$i}; if (not $vlanip) { print "CoreVlanNum $i - No value for CoreVlan_IP_$i\n"; next; } print "CoreVlanNum $i - brip: $brip, vlanip: $vlanip\n"; my $vmask = $server->{'CoreVlan_Netmask_'.$i}; if ($vlanip eq $brip){ my $vlist = join ("/", $brip, $vmask) ; $vlist =~ s/.[0-9]*\//.0\//g; push(my @vnwlist, $vlist) if ! $seen{$vlist}++; } else { print "vlanip does not match brip\n"; } } print "vnwlist: ", Dumper(\@vnwlist); }
Output:
Count: 1 brlan = n Count: 2 brlan = y CoreLanNum 1 - brip: 192.168.165.16, corebrip: 192.168.156.16 coreip does not match brip CoreLanNum 2 - brip: 192.168.165.16, corebrip: 192.168.156.16 coreip does not match brip brnwlist: $VAR1 = []; CoreVlanNum 1 - brip: 192.168.165.16, vlanip: 192.168.156.16 vlanip does not match brip CoreVlanNum 2 - No value for CoreVlan_IP_2 vnwlist: $VAR1 = []; Count: 3 brlan = y CoreLanNum 1 - brip: 192.169.73.1, corebrip: 192.169.32.1 coreip does not match brip CoreLanNum 2 - brip: 192.169.73.1, corebrip: 192.169.32.1 coreip does not match brip CoreLanNum 3 - brip: 192.169.73.1, corebrip: 192.169.73.1 CoreLanNum 4 - brip: 192.169.73.1, corebrip: 192.169.73.1 brnwlist: $VAR1 = [ '192.169.73.0/255.255.255.240' ];

In reply to Re: Use of uninitialized value $brip in join or string at script.pl line 50 by tangent
in thread Use of uninitialized value $brip in join or string at script.pl line 50 by deep27ak

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.