Re: Combine similar patterns




On Mar 29, 2006, at 8:10, anand kumar wrote:

Hi all,

I have a problem in combining the nested/multiple patterns. The input of the file is as follows:

The problem to answer this message is that looks like the example is a simplification of the real input data, and thus it is difficult to come with a specific solution because you don't know which assumptions taken from the example actually apply.

Anyway, I think the point here is that you know the flip-flop operator, which is .. in scalar context (search perlop for "flip"). This is a program that outputs what you want modulus blank lines to depict its usage, so you can adapt it if it indeed does the job:

@inside = ();
@outside = ();
while (<>) {
next unless /\S/;
my $inside = m{^<f1} .. m{^</f1};
next if m{^</?f1=};
print, next if $inside;
push @outside, $_;
}
print @outside;

If the flip-flop operator does not make sense in the actual input data please write again.

-- fxn

% perl foo.pl input
<f1>
A
B
C
G
H
K
N
O
</f1>
D
E
F
I
J
L
M



.