8 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
package Class;
my %class_hash;
sub new {
my $class = shift;
my $value = shift || 'default';
my $self = { value => $value };
bless $self, $class;
return $self;
}
sub set_class_hash {
my $self = shift;
my ($k, $v) = @_;
$class_hash{$k} = $v;
}
sub get_class_hash {
my $self = shift;
my $k = shift;
return $class_hash{$k};
}
package main;
my $obj1 = new Class('one');
$obj1->set_class_hash('color', 'red');
print Dumper $obj1;
my $obj2 = new Class('two');
print $obj2->get_class_hash('color'), "\n";
print Dumper $obj2;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
package Class;
my %class_hash;
sub new {
my $class = shift;
my $value = shift || 'default';
my $self = { value => $value , class_wide => \%class_hash, };
bless $self, $class;
return $self;
}
package main;
my $obj1 = new Class('one');
$obj1->{class_wide}->{color} = 'red';
print Dumper $obj1;
my $obj2 = new Class('two');
print Dumper $obj2;
8 Einträge, 1 Seite |