summaryrefslogtreecommitdiffstats
path: root/contrib/perl5/eg/travesty
blob: 7e6f983c7ce8cea64bbb3955c1e999e5180f4e9d (plain)
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
#!/usr/bin/perl

while (<>) {
    next if /^\./;
    next if /^From / .. /^$/;
    next if /^Path: / .. /^$/;
    s/^\W+//;
    push(@ary,split(' '));
    while ($#ary > 1) {
	$a = $p;
	$p = $n;
	$w = shift(@ary);
	$n = $num{$w};
	if ($n eq '') {
	    push(@word,$w);
	    $n = pack('S',$#word);
	    $num{$w} = $n;
	}
	$lookup{$a . $p} .= $n;
    }
}

for (;;) {
    $n = $lookup{$a . $p};
    ($foo,$n) = each(lookup) if $n eq '';
    $n = substr($n,int(rand(length($n))) & 0177776,2);
    $a = $p;
    $p = $n;
    ($w) = unpack('S',$n);
    $w = $word[$w];
    $col += length($w) + 1;
    if ($col >= 65) {
	$col = 0;
	print "\n";
    }
    else {
	print ' ';
    }
    print $w;
    if ($w =~ /\.$/) {
	if (rand() < .1) {
	    print "\n";
	    $col = 80;
	}
    }
}
OpenPOWER on IntegriCloud