Thread Hash als Klasseneigenschaft (7 answers)
Opened by Gast at 2005-10-25 20:16

Ronnie
 2005-10-25 20:45
#59299 #59299
User since
2003-08-14
2022 Artikel
BenutzerIn
[default_avatar]
Code: (dl )
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;
\n\n

<!--EDIT|Ronnie|1130258864-->

View full thread Hash als Klasseneigenschaft