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 existsif corelannum existsvnwlist: $VAR1 = [ '192.168.165.0/255.255.255.0 ' ]; vnwlist: $VAR1 = []; vnwlist: $VAR1 = []; vnwlist: $VAR1 = []; vnwlist: $VAR1 = []; vnwlist: $VAR1 = []; vnwlist: $VAR1 = []; vnwlist: $VAR1 = [];
I tried various provided here http://www.perlmonks.org/?node_id=124970brnwlist: $VAR1 = [ '192.169.73.0/255.255.255.0 ' ]; brnwlist: $VAR1 = []; brnwlist: $VAR1 = []; brnwlist: $VAR1 = []; brnwlist: $VAR1 = []; brnwlist: $VAR1 = [];
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 scriptfor 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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |