All pastes #1472642 Raw Edit

Someone

public text v1 · immutable
#1472642 ·published 2009-06-24 14:49 UTC
rendered paste body
#!/usr/bin/perl

#bigrams.pl FILE

use warnings;
use strict;

our ($a, $b);
my %bigrams;
my $x = "";
my $counter = 1;

while (<>) {
	chomp;
	tr/A-Z/a-z/;
	tr/;:,.!\-'"'?{}//d;
	foreach my $wd (split) {
		my $y = $wd;
		my $bigram = "$counter: $x $y";
		$bigrams{$bigram}++;
		$x = $y;
		$counter++;
	}
}

#print "Eine genaue Auflistung der Worthufigkeiten findet sich in resultat.txt\n";

open OUTPUT, ">resultat.txt";

foreach my $w (sort by_number keys %bigrams) {
	print OUTPUT "$w\n";
}

close OUTPUT;


sub by_number {
	 $a <=> $b || $a cmp $b;
}