
mr.fraggs
New User
Feb 14, 2007, 2:26 AM
Post #1 of 4
(424 views)
|
|
2 different xml's for one regex works the other not
|
Can't Post
|
|
Hello all im new to the board, im from germany and programm in perl to generate code reviews. im installing a new code review program called emma and need to pull out some numbers. i wrote a regex wich works great for the test xml wich was created 2 months back but the new xml gives me back weird stuff ... but it looks the same. here is the perl code
# !perl use strict; use warnings; my $dataxml = 'z:\tla\scripts\emmaparser\index.xml'; my $xmlfile; open($xmlfile,'<',$dataxml) or die $!; while(my $line = <$xmlfile>) { if(my ($test, $test1, $test2, $test3)=$line=~m!<\s*coverage\s+type="(block)\s*,\s*\%\s*"\s+value="(\d+)\%\s+\(([\d\.]+)/([\d\.]+)\)"\s*/>!s) { print sprintf("%s %s %s xxx ",$test1,$test2,$test3); last if $test eq 'block' } } while(my $line2 = <$xmlfile>) { if(my ($type, $value1, $value2, $value3)=$line2=~m!<\s*coverage\s+type="(line)\s*,\s*\%\s*"\s+value="(\d+)\%\s+\(([\d\.]+)/([\d\.]+)\)"\s*/>!s) { print sprintf("%s %s %s xxx ",$value1,$value2,$value3); last if $type eq 'line' } } close ($xmlfile); here is my regex for block wich works perfectly with both xml files
~m!<\s*coverage\s+type="(block)\s*,\s*\%\s*"\s+value="(\d+)\%\s+\(([\d\.]+)/([\d\.]+)\)"\s*/>!s this matches the line with coverage and looks at the type (in this case block)
~m!<\s*coverage\s+type="(line)\s*,\s*\%\s*"\s+value="(\d+)\%\s+\(([\d\.]+)/([\d\.]+)\)"\s*/>!s here is the regex for line, wich works perfect with xml file number 1 but in the case of xml file number 2 it jumps one xml tree and takes the numbers from the next segment (wich its not supposed too ...) and here is XML file #1 wich works for block and line EDIT:i guess i cant post URL's ... w w w.mydatabus.com/public/myspaceforyou/z/index.x m l and here is XML fuke #2 wich doesnt work how its supposed to, it jumps a tree and gets the wrong line numbers... EDIT:i guess i cant post URL's ... w w w.mydatabus.com/public/myspaceforyou/z/index2.x m l just remove the spaces between the www and the xml ANY help or hints or thoughts appriciated :chomp: thanks -fraggs :trockon:
|