#!/usr/bin/perl -w
#
# Usage: ./pad.pl columns
#
# Pads the input with zeros to the desired number of columns.

if (scalar(@ARGV) != 1) {
  print STDERR "Usage: pad.pl columns\n";
  exit 1;
}

$cols = shift(@ARGV);
while (<>) {
  chop;
  @array = split(/\s+/);
  $col = scalar(@array);
  if ($col > $cols) {
    die "Found $col columns in the input, cannot pad to $cols columns";
  }
  print;
  while ($col < $cols) {
    print " 0";
    $col++;
  }
  print "\n";
}
