1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#! /usr/bin/env perl
#
# fix-len.pl
# Dictionary maintenance tool - make dictionary line lengths uniform.
# Reads dictionary on stdin, prints it, with a uniform number
# of words per line, to stdout.
#
# Example usage:
# cat en/words/words.adj.2 | ./fix-len.pl
#
# Copyright (C) 2009 Linas Vepstas <linasvepstas@gmail.com>
#
my $linelen = 0;
while (<>)
{
chop;
my @entries = split;
# Loop over the entries
foreach (@entries)
{
my $wd = $_;
$linelen += 1 + length $_;
print "$_ ";
# Insert a newline if the resulting line is too long.
if ($linelen > 60)
{
print "\n";
$linelen = 0;
}
}
}
print "\n";
|