Thanks very much stevieb and tangent.

You guys made my day. I now understand the usage of variables and the place it should be defined. I did tried using subroutines but I believe my script requirement would be fulfilled more by the second method.

Till now the script does works as expected with one loop hole as I see.

After picking up unique values the output contains empty lines as below

If vlannum exists
vnwlist: $VAR1 = [ '192.168.165.0/255.255.255.0 ' ]; vnwlist: $VAR1 = []; vnwlist: $VAR1 = []; vnwlist: $VAR1 = []; vnwlist: $VAR1 = []; vnwlist: $VAR1 = []; vnwlist: $VAR1 = []; vnwlist: $VAR1 = [];
if corelannum exists
brnwlist: $VAR1 = [ '192.169.73.0/255.255.255.0 ' ]; brnwlist: $VAR1 = []; brnwlist: $VAR1 = []; brnwlist: $VAR1 = []; brnwlist: $VAR1 = []; brnwlist: $VAR1 = [];
I tried various provided here http://www.perlmonks.org/?node_id=124970

but nothing seems to work in my case. At one point I have to dump these values in a file and with these empty lines it will not be proper.

Also can someone please help me understand why do we use Data:Dumper ?

my script
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} . "\n" ; if ( $corebrip eq $brip ){ $brlist = join ("/", $brip, $brmask) ; $brlist =~ s/.[0-9]*\//.0\//g; push( @brnwlist, $brlist) unless $seen{$brlist}++; } else { # print "coreip doesnot matches 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} . "\n"; if ($vlanip eq $brip){ my $vlist = join ("/", $brip, $vmask) ; $vlist =~ s/.[0-9]*\//.0\//g; push @vnwlist, $vlist unless $seen{$vlist}++; } } @vnwlist = grep (/\S/, @vnwlist); print "vnwlist: ", Dumper(\@vnwlist); } }

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