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]; }

In reply to pattern match screwed up!! by mdfaizy

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.