Debian Codegraph @

data/tools/fix-len.pl

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