Go to the first, previous, next, last section, table of contents.


インスタンス変数

無名の配列や無名のハッシュには、インスタンス変数を入れておくことができま す。名前付きパラメータの例もいっしょに示しておきます。

package Foo;

sub new {
        my $type = shift;
        my %params = @_;
        my $self = {};
        $self->{'High'} = $params{'High'};
        $self->{'Low'}  = $params{'Low'};
        bless $self;
}

package Bar;

sub new {
        my $type = shift;
        my %params = @_;
        my $self = [];
        $self->[0] = $params{'Left'};
        $self->[1] = $params{'Right'};
        bless $self;
}

package main;

$a = new Foo ( 'High' => 42, 'Low' => 11 );
print "High=$a->{'High'}\n";
print "Low=$a->{'Low'}\n";

$b = new Bar ( 'Left' => 78, 'Right' => 40 );
print "Left=$b->[0]\n";
print "Right=$b->[1]\n";


Go to the first, previous, next, last section, table of contents.

検索式: