deep27ak has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use warnings; use XML::Simple; my $xml = do {local $/='';'network.xml'} ; my $servers = XMLin($xml, ForceArray => 1); my %seen; foreach my $server (@{$servers->{server}}) { my $brlist; my $corebrip; my $brmask; my $brip; my $num; my $brlan; my @node = $server->{NodeName__1} . "\n"; my $lanip = $server->{CoreLanIP_1__1} ; my @mask = $server->{CoreLanNetmask_1} . "\n"; my $network = join("/", $lanip, @mask); $network =~ s/.[0-9]*\//.0\//g; push(my @networklist, $network) if ! $seen{$network}++; $brlan = $server->{BRLAN} ; if ( $brlan eq "y" ) { $brip = $server->{BR_IP}; $num = $server->{CoreLanNum} ."\n" ; } my @brnwlist; for my $n (1..$num){ $corebrip = $server->{'CoreLanIP_'.$n.'__1'} ; $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"; } } for $a (@brnwlist) { if ( $a ne "") { print "empty array"; my $vnum = $server->{CoreVlanNum} ."\n" ; for my $i (1..$vnum){ my $vlanip = $server->{'CoreVlan_IP_'.$i} ; my $vmask = $server->{'CoreVlan_Netmask_'.$i} ."\n"; if ($vlanip eq $brip){ my $vlist = join ("/", $brip, $vmask) ; $vlist =~ s/.[0-9]*\//.0\//g; push(my @vnwlist, $vlist) if ! $seen{$vlist}++; print @vnwlist; } } } } }
Now I am not able to figure out how to define the variable globally grepped from xml so that they can be used anywhere inside my script.
Most importantly I have to run a 'if' condition where if $brlan =y then there are two more conditions.
if the array from first for condition i.e. @brnwlist doesnot contains any value and is empty ( which should happen if $brip ne $corebrip) then second for loop should run searching for $vnum.
But I am not sure how to use these variables all across the foreach my $server (@{$servers->{server}}) loop
my output at the momentInput xmlUse of uninitialized value $brip in string eq at nfs_security.pl line +48. Use of uninitialized value $brip in join or string at nfs_security.pl +line 50. Use of uninitialized value $brmask in join or string at nfs_security.p +l line 50. Use of uninitialized value $num in foreach loop entry at nfs_security. +pl line 44. Use of uninitialized value $corebrip in string eq at nfs_security.pl l +ine 48. Use of uninitialized value $brip in string eq at nfs_security.pl line +48. Use of uninitialized value $brip in join or string at nfs_security.pl +line 50. Use of uninitialized value $brmask in join or string at nfs_security.p +l line 50. Use of uninitialized value $num in foreach loop entry at nfs_security. +pl line 44. Use of uninitialized value $corebrip in string eq at nfs_security.pl l +ine 48. Use of uninitialized value $brip in string eq at nfs_security.pl line +48. Use of uninitialized value $brip in join or string at nfs_security.pl +line 50. Use of uninitialized value $brmask in join or string at nfs_security.p +l line 50. Use of uninitialized value $num in foreach loop entry at nfs_security. +pl line 44. Use of uninitialized value $corebrip in string eq at nfs_security.pl l +ine 48. Use of uninitialized value $brip in string eq at nfs_security.pl line +48. Use of uninitialized value $brip in join or string at nfs_security.pl +line 50. Use of uninitialized value $brmask in join or string at nfs_security.p +l line 50. Use of uninitialized value $num in foreach loop entry at nfs_security. +pl line 44. Use of uninitialized value $corebrip in string eq at nfs_security.pl l +ine 48. Use of uninitialized value $brip in string eq at nfs_security.pl line +48. Use of uninitialized value $brip in join or string at nfs_security.pl +line 50. Use of uninitialized value $brmask in join or string at nfs_security.p +l line 50. coreip doesnot matches brip coreip doesnot matches brip coreip doesnot matches brip coreip doesnot matches brip coreip doesnot matches brip coreip doesnot matches brip coreip doesnot matches brip coreip doesnot matches brip
<servers> <server NodeName__1="mch30-nds-ins" CoreLanNum="2" CoreBondNum="1" CoreVlanNum="1" CoreVlan_IF_1="vlan2603" CoreVlan_IP_1="192.168.156.16" CoreVlan_Netmask_1="255.255.255.0" CoreLanIP_1__1="192.168.156.16" CoreLanNetmask_1="255.255.255.0" CoreLanIP_2__1="192.168.156.16" CoreLanNetmask_2="255.255.255.0" BRLAN="n" /> <server NodeName__1="mch30-nds-insc" CoreLanNum="2" CoreBondNum="1" CoreVlanNum="2" CoreVlan_IF_1="vlan2605" CoreVlan_IP_1="192.168.156.16" CoreVlan_Netmask_1="255.255.255.0" CoreLanIF_1="eth0" CoreLanIP_1__1="192.168.156.16" CoreLanNetmask_1="255.255.255.0" CoreLanIP_2__1="192.168.156.16" CoreLanNetmask_2="255.255.255.0" BR_IP="192.168.165.16" BR_Interface="vlan3525" BRLAN="y" /> <server NodeName__1="nds-test" CoreLanNum="4" CoreBondNum="2" CoreVlanNum="0" CoreLanIP_1__1="192.169.32.1" CoreLanNetmask_1="255.255.255.0" CoreLanIP_2__1="192.169.32.1" CoreLanNetmask_2="255.255.255.0" BR_IP="192.169.73.1" BRLAN="y" CoreLanIP_3__1="192.169.73.1" CoreLanNetmask_3="255.255.255.240" CoreLanIP_4__1="192.169.73.1" CoreLanNetmask_4="255.255.255.240" CoreLanBond__4="bond3" arp_Target_BnR_IP="192.169.73.254" RouteIP_1__1="192.169.73.0" RouteNetmask_1__1="255.255.255.0" RouteGateway_1__1="192.169.73.254" />
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Use of uninitialized value $brip in join or string at script.pl line 50
by stevieb (Canon) on Sep 15, 2015 at 17:05 UTC | |
by deep27ak (Novice) on Sep 15, 2015 at 17:25 UTC | |
by poj (Abbot) on Sep 15, 2015 at 17:57 UTC | |
by deep27ak (Novice) on Sep 16, 2015 at 06:40 UTC | |
|
Re: Use of uninitialized value $brip in join or string at script.pl line 50
by tangent (Parson) on Sep 15, 2015 at 18:39 UTC | |
by deep27ak (Novice) on Sep 16, 2015 at 06:38 UTC | |
|
Re: Use of uninitialized value $brip in join or string at script.pl line 50
by stevieb (Canon) on Sep 15, 2015 at 18:05 UTC |