Thread Hilfestellung bei Problem mit package
(20 answers)
Opened by jan99 at 2015-03-27 08:06
Vielleicht hilft dir das:
Code (perl): (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 package Jan99; sub new { bless({ on=>1 }, shift) } sub log { my $self=shift; $self->{on}=shift if @_; return $self->{on}; } sub shell { my $self=shift; $self->{on}=shift if @_; return $self->{on}; } package Besser; sub new { bless({ log_on => 1, shell_on => 1 }, shift) } sub log { my $self=shift; $self->{log_on}=shift if @_; return $self->{log_on}; } sub shell { my $self=shift; $self->{shell_on}=shift if @_; return $self->{shell_on}; } package main; use 5.14.0; sub show { my $t = shift; say "Log: ", $t->log(), ", Shell: ", $t->shell(); } sub test { my $t = shift; say "Original: "; show($t); say "Setting log(0)"; $t->log(0); show $t; say "Setting shell(1)"; $t->shell(1); show $t; say "Setting log(1)"; $t->log(1); show $t; } say "Testing Jan99"; test(Jan99->new()); say "Testing Besser"; test(Besser->new()); |