>  Feel free to check them out, even if you are not taking part in
>  the Games, and let me know what you think:
>
>   
> http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/experts.mspx
>
>  I have solutions for all 10 events, but I haven't written
>  all the write-ups yet.  So any feedback on the style /content
>  would be welcome.  Note that this is the Advanced Perl division,
>  so I assume readers are familiar with Perl and all the basic
>  concepts.

I really liked that you discussed good style and some defensive
coding, even though that wasn't required by the competition.  For
"open or die" -- I personally think it's good style to die with at
least "$!" so there's some feedback as to what happened.

My solution was slightly more direct -- each number can be mapped to a
regex character class.  (e.g. 2 is [ABC])  So convert the number to a
regex expression, loop the file until something matches the regex, and
print it out.

use strict;
use warnings;
use 5.010;

my @num2chars=split ':', '::abc:def:ghi:jkl:mno:prs:tuv:wxy';
say "Enter a seven-digit phone number:";
my $regex = join q{}, map { "[$num2chars[$_]]" } split //, <STDIN>, 7;
open my $dict, 'C:\Scripts\wordlist.txt' or die $!;
while ( my $line = uc <$dict> ) { say($line), last if $line =~ /^$regex$/i }

Regards,
David
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to