A classic opportunity for the flip-flop operator.
A bit tricky ... Until you reach BEGIN CERTIFICATE, the if{} is false, so we don't save the lines we read, but @extract is empty, so we continue around the loop. Once we reach the interesting region, we save the lines, and short-circuit the loop to continue reading. After we reach the end, the array has a size, so it is boolean true, and the loop terminates.
open my $file, '<', $filename or die "Could not open $filename $!.\n"; my @extract; FILE: while (<$file> ) { chomp; if ( /BEGIN-CERTIFICATE/ .. /END-CERTIFICATE/ ) { push @extraction, $_; next FILE; } last $FILE if @extract; }
As Occam said: Entia non sunt multiplicanda praeter necessitatem.
In reply to Re: How to slurp up multi lines between two markers
by TomDLux
in thread How to slurp up multi lines between two markers
by symgryph
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |