I decided to enter the 2008 Winter Scripting Games. I managed to get full points for the first event but screwed up and didn't notice the deadline for the second.
Here's my entry for the first. It seems a bit simpler than Jan's solution and avoids an eval. I'll try to do a better job with commentary for the latter events.
#!/usr/bin/perl -w
use strict;
print "Enter phone number: ";
chomp(my $phone = <STDIN>);
my %letters;
{
my @L = ('A'.. 'P', 'R' .. 'Y');
my $n = 2;
while (my @t = splice @L, 0 => 3) {
$letters{$n++} = sprintf '[%s%s%s]', @t;
}
}
my $match = '^' . join('', map $letters{$_}, split//, $phone) . '$';
open my $in, '<c:/Scripts/WordList.txt'
or die "Can't read wordlist: $!\n";
while (<$in>) {
tr/a-z/A-Z/;
if (/$match/o) { print; last }
}
close $in;
Winter Scripting Games 0 Comments More | Login | Reply /