Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Pattern search in a Multiline Record, from a multi-record datafile.
by BrowserUk (Patriarch) on Mar 02, 2012 at 04:50 UTC | |
|
Re: Pattern search in a Multiline Record, from a multi-record datafile.
by bitingduck (Deacon) on Mar 02, 2012 at 06:24 UTC | |
|
Re: Pattern search in a Multiline Record, from a multi-record datafile.
by TJPride (Pilgrim) on Mar 02, 2012 at 18:20 UTC | |
by Anonymous Monk on Mar 08, 2012 at 21:26 UTC |