Winter Scripting Games

gav on 2008-02-22T01:12:34

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 = );

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, ') {
    tr/a-z/A-Z/;
    if (/$match/o) { print; last }
}
close $in;