File: delete.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 (72 lines) | stat: -rwxr-xr-x 1,225 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#! /usr/bin/env perl
#
# delete.pl
#
# Dictionary maintenance tool - delete words from dictionary.
# Given a list of words and a dictionary file, this script
# will delete the words from the file.
#
# It is assumed that the word-list holds one word per line,
# and that the word-list is already in alphabetical order.
#
# Example usage:
# ./delete.pl wordlist_file en/words/words.adj.1
#
# Copyright (C) 2009 Linas Vepstas <linasvepstas@gmail.com>
#

if ($#ARGV < 1)
{
	die "Usage: delete.pl wordlist-file dict-file\n";
}

# Get the word-list, and the dictionary, from the command line
my $wordlist_file = @ARGV[0];
my $dict_file = @ARGV[1];

open(WORDS, $wordlist_file);
my @words = ();
while (<WORDS>)
{
	# Get rid of newline at end of word.
	chop;
	push @words, $_;
}
close(WORDS);

my $word = shift @words;

open (DICT, $dict_file);
while (<DICT>)
{
	chop;
	my @entries = split;

	# Loop over the entries
	$gotone = 0;
	foreach (@entries)
	{
		my $entry = $_;
		while (($entry gt $word) && ($word ne ""))
		{
			$word = shift @words;
		}
		if ($entry ne $word)
		{
			# print "$entry ";
			print "$entry";
			$gotone = 1;
		}
		else
		{
			$word = shift @words;
		}
	}
	if ($gotone)
	{
		print "\n";
	}
}
close (DICT);