Quote:
Originally Posted by czezz
Looks good
The only thing is that case lines are duplicated but it is a small problem.
|
This is really strange. Looking at the code there is no way you can get the case line twice, unless you have two consecutive case lines in the original input.
Quote:
Can I have a little explanation of what is going on in code ?
|
Of course. The whole code starts every time it encounter a line containing the "case" pattern. First it simply print that line, then starts a while loop which ends when it encounters the "details" pattern. This is one of the assumptions: each section should always end with a "details" line.
Then it stores lines in two diffrent arrays. Array0 contains lines which begin with a "@", array1 stores all the rest:
Code:
if ( $1 ~ /^@/ ) {
array0 is pouplated
}
else {
array1 is populated
}
When the while loop ends, it prints the content of the arrays in revers order: first array1, then array0. All the lines in the array1 are printed except the last one (that one containing "details"), which in turn is printed after array0.
Finally it deletes the content of the arrays and reset the counters. When it encounters the next "case" line the code is run again.
If you have problems with the duplicated case, please attach the actual input file to your post, so I can try to process it on my machine and discover the bug. I don't remember if the ability to attach files is reserved to "Senior Members". Eventually you can e-mail me (you can find a link to send an e-mail in my LQ profile).