File: fix-len.pl

package info (click to toggle)
link-grammar 4.7.4-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 5,872 kB
  • ctags: 3,004
  • sloc: ansic: 20,018; sh: 10,181; cpp: 5,221; asm: 2,017; java: 1,314; makefile: 389; perl: 274; yacc: 104
file content (37 lines) | stat: -rwxr-xr-x 630 bytes parent folder | download | duplicates (6)
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";