#!/usr/bin/env perl -n -pi
our $prevn;
BEGIN {
$prevn = 0;
print STDERR "
Contents
\n\n";
}
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};
}
END { print STDERR "\n\n" }