携帯メッセージ

Problem A: Keitai Message via id:zyxwv:20070710:1184076463

#!/usr/bin/env perl
use strict;
use warnings;

sub decode($){
    my ($str) = @_;
    return '' unless $str;

    my %table = ('1'=>' ,!?',
		 '2'=>'abc',
		 '3'=>'def',
		 '4'=>'ghi',
		 '5'=>'jkl',
		 '6'=>'mno',
		 '7'=>'pqrs',
		 '8'=>'tuv',
		 '9'=>'wxyz');

    my $c = substr($str,0,1);
    my $index = ((length $str)-1) % (length $table{$c});
    substr($table{$c},$index,1);
}

while(<>){
    s/(([1-9])\2*)?0/decode $1/ge;
    print;
}
  • 無限リストはずっこい
  • s/.../.../geのeは、evalのe