#!/usr/bin/env perl
use English;
$INPLACE_EDIT=1;
our $prevn;
BEGIN {
$prevn = 0;
print STDERR "
Contents
\n\n";
}
while (<>)
{
if (m{
( # 4. header
([^(]+)?.+? # 5. label
)
}x) {
my ($hn, $id, $val, $label) = ($1, $2, $3, $4);
if ($prevn) {
if ($hn != $prevn) {
print STDERR $hn > $prevn
? $hn - $prevn > 1
? "" : "\n" : $prevn - $hn > 1
? "
\n" : "\n";
$prevn = $hn;
} else {
print STDERR "\n"
}
} else {
$prevn = $hn;
}
print STDERR qq{$val};
$_ = qq{$val\n};
}
}
continue
{print}
END { print STDERR "\n\n" }