Re: Combine similar patterns
- From: fxn@xxxxxxxxxxx (Xavier Noria)
- Date: Wed, 29 Mar 2006 09:14:35 +0200
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
.
- References:
- Combine similar patterns
- From: Anand Kumar
- Combine similar patterns
- Prev by Date: Combine similar patterns
- Next by Date: Re: How to extract the path of the file name in perl
- Previous by thread: Combine similar patterns
- Next by thread: Re: Combine similar patterns
- Index(es):