in reply to Get specified number of previous line text when encountered a text match in a file
This assumes that you'll never see D: without first seeing A: and B: in the same record.
my ( $adata, $bdata ); while ( <DATA> ) { chomp; m/^A:\s*(\S)$/ and $adata = $1; m/^B:\s*(\S)$/ and $bdata = $1; m/^D:/ and do { print "A: $adata, B: $bdata\n"; last; }; }
Dave
|
|---|