File: count.pl

package info (click to toggle)
gramadoir 0.7-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 12,604 kB
  • ctags: 198
  • sloc: perl: 11,207; sh: 3,016; xml: 462; lisp: 196; makefile: 148; yacc: 63; lex: 62; ansic: 26; sed: 16
file content (31 lines) | stat: -rw-r--r-- 579 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/perl
# Copyright (C) 2004 Kevin P. Scannell
# This is free software; see the file COPYING for copying conditions.  There is
# NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

# Usage:
# $ cat wordlist.txt | count.pl freqs.txt

use strict;
use warnings;

my %freqhash;
open (FREQ, "$ARGV[0]");
while(<FREQ>) {
	chomp;
	my ($word,$freq) = split;
	$freqhash{$word} = $freq;
}
while (<STDIN>) {
	my $line = $_;
	chomp;
	s/ .*//;
	my $ans = $freqhash{$_};
	if (defined $ans) {
		print "$ans $line";
	}
	else {
		print "0 $line";
	}
}
exit 0;