#!/usr/bin/perl
# The Missing Textutils, Ondrej Bojar, obo@cuni.cz
# http://www.cuni.cz/~obo/textutils
#
# 'numerize_blocks' adds a tab-delimited prefix to each block (blocks are
# delimited by a blank line) such that each block gets a distinct number.
#
# Useful in combination with 'blockwise --auto-prefix' or 'grp'
#
# $Id: numerize_blocks,v 1.5 2013-06-17 19:04:41 bojar Exp $
#

use strict;
use Getopt::Long;

my $squeeze = 0;
my $start = 1;
my $format = "%i";
GetOptions(
  "squeeze" => \$squeeze,
  "start=i" => \$start,
  "format=s" => \$format,
) or exit 1;

my $n = $start;
while (<>) {
  if (/^$/) {
    $n++;
    print if !$squeeze;
    next;
  }
  printf "$format\t%s", $n, $_;
}
