Perl/クラスを作成する
関連
- Perl
概要
Perlでクラスを作成する
方法
#!/usr/bin/perl
{
package Hoge;
# コンストラクタ
sub new {
my $class = shift;
my $this = {
foo = 10,
};
return bless $this, $class;
}
# メソッド
sub getFoo {
my $this = shift;
return $this->{foo};
}
}
{
package main;
$hoge = new Hoge();
print $hoge->getFoo() . "\n";
}
解説
ポイントは
- パッケージ分割
- shift(引数)
- bless
えっと、急ぎメモなので正直良く分かってないです。
参考
- http://rfs.jp/sb/perl/04/02.html
作成日 2013-08-17
