/usr/share/doc/libnews-scan-perl/examples/avg-addy is in libnews-scan-perl 0.53-3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | #! /usr/bin/perl -w
# avg-addy - compute the average of a list of email addresses
# Copyright (c) 1998. Greg Bacon. All Rights Reserved.
# This program is free software. You may distribute it or modify it
# (perhaps both) under the terms of the Artistic License which comes
# with the Perl Kit.
use strict;
use integer;
my @name;
my $namelen = 0;
my @hname;
my @hnamelens;
my $total = 0;
my $total_parts = 0;
while (<>) {
chomp;
next unless /\S/; ## blank lines suck
next unless /.@./;
my($i,$j);
$total++;
s/^(.*?)@//;
my $name = $1;
$namelen += length $name;
my @parts = split /\./, $_;
$total_parts += @parts;
$i = 0;
foreach my $ch (split //, $name) {
$name[$i] ||= 0;
$name[$i] += ord($ch);
$i++;
}
$i = 0;
foreach my $part (@parts) {
$hnamelens[$i] ||= 0;
$hnamelens[$i] += length $part;
$j = 0;
foreach my $ch (split //, $part) {
$hname[$i][$j] ||= 0;
$hname[$i][$j] += ord($ch);
$j++;
}
$i++;
}
}
my $avg = '';
## cull what we don't need
my $avg_name_len = $namelen / $total;
splice @name, $avg_name_len;
my $avg_num_parts = $total_parts / $total;
splice @hname, $avg_num_parts;
splice @hnamelens, $avg_num_parts;
foreach my $n (@name) {
$avg .= chr($n / $total);
}
$avg .= '@';
for (my $i = 0; $i < @hname; $i++) {
my $avg_len = $hnamelens[$i] / $total;
splice @{$hname[$i]}, $avg_len;
foreach my $n (@{$hname[$i]}) {
$avg .= chr($n / $total);
}
$avg .= '.';
}
$avg =~ s/\.$//;
print "Average address: $avg\n";
|