in reply to Matching over two lines
Three problems:
"|" is a special character in regexps. It needs to be escaped.
You will look for "MSG-HDR" and "|UB" on the same line. The following would match:
MSG-HDR |UB
The next in the code below fixes this.
$orderfound is not always cleared when it should be. The following would match:
MSG-HDR bla |UB
Or maybe that's ok? If it's ok, keep the $orderfound = 0; where it was.
Fix:
my $orderfound = 0; while (my $line = <>) { if ($line =~ /MSG-HDR/) { $orderfound = 1; next; } if ($orderfound && $line =~ /\|UB/) { print "$line\n"; } $orderfound = 0; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Matching over two lines
by TrekNoid (Pilgrim) on Mar 30, 2006 at 17:34 UTC |