My file looks like this:
<MAIN>
<SUB_MAIN>one</SUB_MAIN>
<VER>version#</VER>
(OTHER STUFF...)
<LOCATION>PATH</LOCATION>
</MAIN>
<MAIN>
<SUB_MAIN>two</SUB_MAIN>
<VER>version#</VER>
(OTHER STUFF...)
<LOC>PATH</LOC>
</MAIN>
What I want to do is to search for the value of SUB_MAIN
lets say one, and if I find it then look for the value of LOCATION
. Go to that location do some syncing get a new version from there and update the VER
information.
My current code has like three loops and is ugly. The skeleton is like this:
$value = "one|two|three";
# for each line in file
while ($line < @FileDat) {
# see if it is a sub module?
if ( $line =~ /\<SUB_MAIN\>$value\<\/SUB_MAIN\>/ )
{
$found_it = 0;
while (!$found_it)
{
$lineNum++;
if ( $FileDat[$lineNum] =~ /\<VER\>\d+\<\/VER\>/ )
{
$currIndex = $lineNum;
while(1)
{
$lineNum++;
if ( $FileDat[$lineNum] =~ /\<LOC\>(.+)\<\/LOC\>/ )
{ #DO SOME STUFF...
$found_it = 1;
last;
}
}
#replace version #
$FileDat[$currIndex] = " <VER>$latestChangeList</VER>\n";
}
}
}
$lineNum++;
}
# write the modified array to new file
print NEWCFGFILEPTR @FileDat;
close(OPEN_FILES);
How can I make it better?
Thank you.