http://qs321.pair.com?node_id=1114076

mdfaizy has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks...Since morning I wrote a complete code to parse an XML file for just few information. However my code breaks in the first section itself when I do a substitute function to remove leading space in a line of the XML. Moreover none of the patter match is working. I am going crazy trying to find out why....any help is higly appreciated. I have tried this code on an Activestate perl installation at office (latest version)and also on my ubuntu perl installation (v5.18.2) and it did not work on either of them. Here is my code:
#!/usr/local/bin/perl # header modules ##################################################### +##################################################################### +########## ###################################################################### +##################################################################### +########## #read the input xml files for the TestSuite tags and its content open(SandBoxXML,$ARGV[0]) || die("sandbox xml file cannot be loaded;ch +eck for file name or existance"); my @sandboxxml = <SandBoxXML>; close(SandBoxXML); #chomp(@sandboxxml); for($i=0;$i<@sandboxxml;$i++) { $sandboxxml[$i] =~ s/^\s+//; #remove leading white spaces and tabs + from each line print $sandboxxml[$i]; #for testing } ###################################################################### +##################################################################### +########## #collecting the required data from the XML dump for($i=0;$i<@sandboxxml;$i++) { #print $sandboxxml[$i]; #for testing if($sandboxxml[$i] =~ /\<TestSuite\>/) { #$i++; #print $sandboxxml[$i]; #for testing while($sandboxxml[$i] !~ /\<\/TestSuite\>/) { if($sandboxxml[$i] =~ /\<ElementName\>/) { my $tsnumber=&readtagdata; #push(@data,$data.","); } if($sandboxxml[$i] =~ /\<Name\>/) { my $tsname=&readtagdata; #push(@data,$data.","); } if($sandboxxml[$i] =~ /\<ATC\>/) { #$i++; while($sandboxxml[$i] !~ /\<\/ATC\>/) { if($sandboxxml[$i] =~ /\<ElementName\>/) { my $atcnumber=&readtagdata; #push(@data,$data.","); } if($sandboxxml[$i] =~ /\<Name\>/) { my $atcname=&readtagdata; #push(@data,$data.","); } if($sandboxxml[$i] =~ /\<Purpose /) { my $atcpurpose=&readtagdata; #push(@data,$data.","); } if($sandboxxml[$i] =~ /\<Requirement\>/) { #$i++; while($sandboxxml[$i] !~ /\<\/Requirement\>/) { if($sandboxxml[$i] =~ /\<ElementName\>/) { my $reqnumber=&readtagdata; #push(@data,$data.","); } if($sandboxxml[$i] =~ /\<Name\>/) { my $reqname=&readtagdata; #push(@data,$data.","); } push(@data, $tsnumber.",".$tsname.",".$atc +number.",".$atcname.",".$atcpurpose.",".$reqnumber.",".$reqname."\n") +; $i++; } } $i++; } } $i++; } } } ###################################################################### +##################################################################### +########## # making the output file open(OUTPUT, ">TestSuite.csv") || die("Cannot make the outpur file...G +OD knows for what reason"); #for testing print OUTPUT @data; #for testing close(OUTPUT); ###################################################################### +##################################################################### +########## #sub functions sub removespace { foreach(@sandboxxml) { $_ =~ s/^[ \t]+//; #remove leading white spaces and tabs from +each line chomp($_); #remove newline character from each line } } sub readtagdata { my @tmp0 = split(/\>/,$sandboxxml[$i]); my @tmp1 = split(/\</,$tmp0[1]); return $tmp1[0]; }