Hi I have two files ,the first data.xml which contain 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>
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
you.pl 24-28 they.pl 36 them.pl 44-49 you.pl 234 77
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 line
<message><file>you.pl</file><line>25</line><type>warning</type><codee> +355</codee><extra>sente</extra>
to an output file .... Now, I am trying to do this somehow, but xml is not an easy to parse ..
open(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"; } }
can someone tell me how to do that or give me a hint :) thanks

In reply to xml parsing by DS

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.