-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglob.pl
41 lines (31 loc) · 786 Bytes
/
glob.pl
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
use feature qw(say);
{
package Test;
our @fields = qw(id name money);
sub new {
my ($class, %args) = @_;
bless { %args }, $class;
}
for my $f (@fields) {
no strict 'refs';
*$f = sub {
if ((scalar @_) > 1) {
my ($self, $val) = @_;
$self->{$f} = $val;
} else {
shift->{$f};
}
};
sub string {
my $self = shift;
say "\ndumping object $self";
say "id=".$self->id;
say "name=".$self->name;
say "money=".$self->money;
}
}
}
my $t = new Test(id => "irr", name => "Ivan", money => 60000);
$t->string();
$t->id("irr2");
$t->string();