I have a tricky situation. I have a data dump file which contains multiple records in an xml based formating. Each record starts with <ticket .... > and ends with </ticket>. The entire dumpfile is fed into this script and stored in an array.

example of a record entry:
<ticket ... state="...." ....> <version="1.23.4.8"> .... <task> ... </task> .... </ticket>

I have to remove certain records from this data dump which are not needed (based on some conditions) and then perform certain actions on the contents of the "<task> ... </task>" portion of each remaining record. The conditions to be met on each record are:

1. Each Record that contains a certain "state" value, needs to be removed/deleted/not printed in the output. The static list of "state's" is fed into this perl program from a another file.

2. And each Record that has an older version number (comparing only the first 2 digits), needs to be removed. Since the version data in the dupm file is not always just numbers, I also need to delete all those records which have a non-digit charecter in the "version" value. Once these 2 conditions are met, there is other processing done on the <task> entry of each record.

The problem I'm facing is that when I'm running my foreach loop on this dumpfile array, either only able to delete the first line of the record that matches condition 1, but not the full record OR only the line of the record that meets conditon 2, but not the full record. I'm hopting someone can help me figure this out.

The base "verion" number I need to compare each record's (first 2 digits only) "version" number is split and stored in an array variable @base_ver (for example: the value 1.20 was split into 1 and 20 and stored)

My loop is:
foreach(@code){ if (m/^<ticket .*state="(.*)") { $state = $1; } if (m/version="/){ my @vers = split(/="(.*)"/); $version_a = $version[1]; $version_a =~ s/(^[A-Za-z]+)|\.[A-Za-z]+$//; if ($version_a ne '') { my @vers = split(/\./, $version_a); #### Now I compare the 2 versions........ } } ### Now I process the tasks if (m/<task/){ ## do some stuff } print; print "\n"; }

This is not working. Perl monks. Do help.


In reply to Pattern search in a Multiline Record, from a multi-record datafile. by Anonymous Monk

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.