I am writting a following code to parse this xml but not able yo understand that why the value of $bsc_id_1 getting changed. here is my code
use strict; use warnings; my $xml_file_to_read = "BSC-19478.xml"; my $counter = 1; my $bsc_id_1; my $bsc_id; open my $RFH,'<',$xml_file_to_read or die "Can't open $xml_file_to_read $!\n"; while(<$RFH>) { chomp; if (($bsc_id_1) = /<BSC id="(.*?)"/ and $counter == 1){ print "BSC1=[$bsc_id_1]\n"; next; } if (! m{</BSC>} and $counter == 1) { print "1\n"; next; } if (($bsc_id) = /<BSC id="(.*?)"/ and $counter == 0){ print "LINE=[$_]\n"; print "BSC1=[$bsc_id_1]\n"; print "BSC2=[$bsc_id]\n"; if ("$bsc_id" eq "$bsc_id_1") { $bsc_id = $bsc_id_1; } } $counter = 0; print "COUNTER=[$counter]\n"; #exit 0; } close($RFH); and here is my output perl parse_xml.pl BSC1=[AMIBRB1] 1 1 1 1 1 1 1 1 COUNTER=[0] LINE=[ <BSC id="BAYHAB1">] BSC1=[BAYHAB1] BSC2=[BAYHAB1] COUNTER=[0] COUNTER=[0] COUNTER=[0] COUNTER=[0] COUNTER=[0] COUNTER=[0] COUNTER=[0] COUNTER=[0] COUNTER=[0] COUNTER=[0] On Thu, Mar 15, 2012 at 8:31 PM, Anirban Adhikary < anirban.adhik...@gmail.com> wrote: > Hi List , > I have a xml file which looks like > > <BSC id="AMIBRB1"> > <ALPHA>10</ALPHA> > <AMRCSFR3MODE>1,3,4,7</AMRCSFR3MODE> > <AMRCSFR3THR>12,16,21</AMRCSFR3THR> > <AMRCSFR3HYST>2,3,3</AMRCSFR3HYST> > <AMRCSFR4MODE>1,3,6,8</AMRCSFR4MODE> > <AMRCSFR4THR>12,17,25</AMRCSFR4THR> > <PAGBUNDLE>50</PAGBUNDLE> > <USERDATA>AMI_BRANLY_B_1</USERDATA> > </BSC> > <BSC id="BAYHAB1"> > <ALPHA>10</ALPHA> > <AMRCSFR3MODE>1,3,4,7</AMRCSFR3MODE> > <AMRCSFR3THR>12,16,21</AMRCSFR3THR> > <AMRCSFR3HYST>2,3,3</AMRCSFR3HYST> > <AMRCSFR4MODE>1,3,6,8</AMRCSFR4MODE> > <REEST>ON</REEST> > <REPFACCH>ON</REPFACCH> > <BCCHNORMAL>0</BCCHNORMAL> > </BSC> > > I need to create a new xml file from this xml. > Now I need to store the first BSC id and need to check it against the > other BSC ids. If both ids are same then I need to write the the contents > of between the BSC id tag in a new xml file. >