I played around for a bit and did a bunch of cleanup. I'm not sure if this does exactly what you're after, but it shows a much better structure that you should be able to follow.

The biggest thing is that I got rid of all the variable definitions near the top. It's much easier to troubleshoot when you declare your variables immediately before use where possible.

This code surely needs more work, but I did what I could with the time I had. Also note that it doesn't look like you use @networklist, but I left it in anyways.

use strict; use warnings; use XML::Simple; use Data::Dumper; my $xml = do {local $/='';'in.xml'} ; my $servers = XMLin($xml, ForceArray => 1); my %seen; my @networklist; my @brlist; my @vlist; for my $server (@{$servers->{server}}){ my $node = $server->{NodeName__1}; my $lanip = $server->{CoreLanIP_1__1}; my $mask = $server->{CoreLanNetmask_1}; my $network = join("/", $lanip, $mask); $network =~ s/.[0-9]*\//.0\//g; push @networklist, $network if ! $seen{$network}++; if ($server->{BRLAN} eq "y" ){ core_lan($server); } else { core_vlan($server); } } # output print "\nBRNW LIST\n"; print Dumper \@brlist; print "\nVLAN LIST\n"; print Dumper \@vlist; exit(0); # # subroutine definitions # sub core_lan { my $server = shift; my $brip = $server->{BR_IP}; my $num = $server->{CoreLanNum}; for (1..$num){ my $corebrip = $server->{'CoreLanIP_'.$_.'__1'}; my $brmask = $server->{'CoreLanNetmask_'.$_}; if ($corebrip eq $brip){ my $brlist = join ("/", $brip, $brmask); $brlist =~ s/.[0-9]*\//.0\//g; push @brlist, $brlist unless $seen{$brlist}++; } else { print "coreip doesnot matches brip\n"; } } } sub core_vlan { my $server = shift; my $brip = $server->{BR_IP}; my $vnum = $server->{CoreVlanNum}; for (1..$vnum){ my $vlanip = $server->{'CoreVlan_IP_'.$_}; my $vmask = $server->{'CoreVlan_Netmask_'.$_}; if ($brip && $vlanip eq $brip){ my $vlist = join ("/", $brip, $vmask); $vlist =~ s/.[0-9]*\//.0\//g; push @vlist, $vlist if ! $seen{$vlist}++; } } }

In reply to Re: Use of uninitialized value $brip in join or string at script.pl line 50 by stevieb
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.