where the fist number appear in each line is a line number in that code now in my second file which is Changes.txt , I have the following<?xml version="1.0" ?> <output> <message><file>me.pl</file><line>23</line><type>note</type><codee>345< +/codee><extra>sente</extra> <message><file>you.pl</file><line>25</line><type>warning</type><codee> +355</codee><extra>sente</extra> <message><file>hi.pl</file><line>21</line><type>note</type><codee>358< +/codee><extra>sente</extra> <message><file>she.pl</file><line>123</line><type>warning</type><codee +>3583</codee><extra>sente</extra> <message><file>they.pl</file><line>231</line><type>warning</type><code +e>3582</codee><extra>sente</extra> <message><file>them.pl</file><line>26</line><type>note</type><codee>33 +58</codee><extra>sente</extra> </output>
which are lines that changed in a code, 24-28 means 24 to 28 ... so what I need to do is reading from the Changes.txt file each line and see if the .pl file appears in the first file data.txt , if it does then I want to see if the lines number matches or in the same range and it is a warning , if it match and it is a warning then I want to get the hole line and send it to a file . example you.pl appears in both files the lines for you.pl in the Changes.txt are 24 to 28 and in data.txt is 25 , line 25 which is in the range of 24-28 appear and it is a warning so that is what I am looking for so I copy the hole lineyou.pl 24-28 they.pl 36 them.pl 44-49 you.pl 234 77
to an output file .... Now, I am trying to do this somehow, but xml is not an easy to parse ..<message><file>you.pl</file><line>25</line><type>warning</type><codee> +355</codee><extra>sente</extra>
can someone tell me how to do that or give me a hint :) thanksopen(CHANGES, "< $linesChangedList") or die "could not open file"; my $myFile = $myFile0; while (<CHANGES>) { chomp; $info = $_; # is it a range or a single line? if ($info =~ /(\d+)-(\d+)/) { $changes{$myFile0} .= " ".join(" ",($1 .. $2))." "; } else { $changes{$myFile0} .= " $info "; } } close(CHANGES); while (<DATA>) { chomp; # split the line from the wave characters my ($file, $line, $type, $rest) = split(/~/, $_, 4); # was this file found in the previous loop? if (defined $changes{$file}) { # was it a range? if (defined $changes{$file}->[1]) { # skip if this $line is not in this range next unless ($line gt $changes{$file}->[0] and $line lt $changes +{$file}->[1]); } else { # skip if this $line is not equal to this single line number next unless $line eq $changes{$file}->[0]; } # if we are here, then this is a match. so print it. print "$_\n"; } }
In reply to xml parsing by DS
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |