Tuesday, March 27, 2007

ハッシュに関数を入れてみる perl

携帯向けサイトなどで使えそうな感じですね。

my %controller = (
i => \&i_page,
e => \&e_page,
y => \&y_page,
);

my $ca = "i";

$controller{$ca}->("iii") if $ca eq "i";
$controller{$ca}->("eee","test2")if $ca eq "e";
$controller{$ca}->("yyy") if $ca eq "y";


sub i_page{
my $str = shift;
print $str;
}

sub e_page{
my ($str,$str2) = @_;
print $str,$str2;
}

sub y_page{
my $str = shift;
print $str;
}

No comments: