/[bfilter]/trunk/bfilter.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/bfilter.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations)
Tue Sep 7 08:33:53 2004 UTC (19 years, 7 months ago) by dpavlin
File MIME type: text/plain
File size: 1019 byte(s)
initial import into svn: linear search version

1 #!/usr/bin/perl -w
2 #
3
4 use strict;
5 use locale;
6
7 # maximum entries
8 my $max = 0;
9 # minimum letters to search by
10 my $min_len = 2;
11
12 sub print_file {
13 my $f = shift || return;
14 open(F, $f) || die "$f: $!";
15 while(<F>) {
16 print;
17 }
18 close(F);
19 }
20
21 print qq{
22 var headlines = Array();
23 };
24
25 my @part_arr;
26 my $last_part = '';
27 my $total = 0;
28
29 while(<STDIN>) {
30 chomp;
31
32 # escape single quote
33 s/'/\\'/g;
34
35 # split into min_len part and rest
36 my ($part,$rest) = ( substr($_,0,$min_len), substr($_,$min_len) );
37
38 # make part lowercase
39 $part = lc($part);
40
41 $last_part = $part if (! $last_part);
42
43 # new part?
44 if ($part ne $last_part) {
45 print "headlines['$last_part'] = Array(\n ",join(",\n ",@part_arr),");\n" if (@part_arr);
46 $total += $#part_arr;
47 @part_arr = ();
48 $last_part = $part;
49 }
50 push @part_arr, "'$_'";
51
52 # break out?
53 last if ($max && $total > $max);
54 }
55
56 print "headlines['$last_part'] = Array(\n ",join(",\n ",@part_arr),");\n" if (@part_arr);
57 print "var min_len = $min_len;\n";
58 print "// index elements: $total\n";

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26