CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
2 different xml's for one regex works the other not

 



mr.fraggs
New User

Feb 14, 2007, 2:26 AM

Post #1 of 4 (575 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

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

Code
~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)


Code
~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:


mr.fraggs
New User

Feb 14, 2007, 4:49 AM

Post #2 of 4 (572 views)
Re: [mr.fraggs] 2 different xml's for one regex works the other not [In reply to] Can't Post

fixed ... instead of dots there were commas so thats what threw my regular expression off. Cool


davorg
Thaumaturge / Moderator

Feb 15, 2007, 7:37 AM

Post #3 of 4 (561 views)
Re: [mr.fraggs] 2 different xml's for one regex works the other not [In reply to] Can't Post

Parsing XML with regular expressions is incredibly fragile. CPAN has dozens of modules for processing XML. Why not use one of those?

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


mr.fraggs
New User

Feb 16, 2007, 4:01 PM

Post #4 of 4 (547 views)
Re: [mr.fraggs] 2 different xml's for one regex works the other not [In reply to] Can't Post

well i would love to use an xml parser and just get it over with. the issue is at work were behind on installing modules and different people will need to use the script, so its using a network install of perl.

since our IT department is so darn slow it would take 2 to 4 months to get one module installed and i just cant wait for that.

thanks for your concern ;)

-fraggs

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives