Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parse/modify files

Status
Not open for further replies.

xenia123

Technical User
Dec 6, 2005
25
SE
Hello ladies and gents

I'm a newbie in perl and i wan't to sove the following task in perl (think would be the best)

Description: I have several files which are called textA.xml and textB.xml, textC.xml and so on (same location)
Now: i have to parse these files and search for block1 and block2. It is possible, that block1 is several times in the file and no block2 and other way round. If one or more of block1 or block2 exists (in each file), i have to add specific lines (line1 belongs to block1 and line2 belongs to block2) under the last line of the specific block.

block1:
<hello>Y</hello>
<gaga>sas</gaga>
<bla>no</bla>

block2
<hello>N</hello>
<gugus>asd</gugus>

line1:
<include>y</include>
<string></string>

line2:
<exclude>n</exclude>
<test>match</test>

I hope, that my question is not to weird ;)

Thank you in forward,

xenia
 
Try something like:
<code>
open (READ, "texta.xml")
while(<READ>)
{
if($block1 == true) #block one is definite
{
open(WRITE, ">texta.xml");

}
if($block1 == 2) #two lines of block 1 match
{
if(m!<bla>no</bla>!)
{
$block1 = true;
}
}
if($block1 == 1) #one line of block 1 matches
{
if(m!<gaga>sas</gaga>!)
{
$block1 = 2;
}
}
if(!<hello>Y</hello>!)
{
$block1 = 1;
}
</code>
it's not perfected, but i'll work on it
 
in fact scratch that

--------------------------
The best answer to your question will definitely be RTFM.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top