Leser: 2
|< 1 2 >| | 17 Einträge, 2 Seiten |
1 2 3 4 5
use strict; use ca; $sandHeap = ca->new(5,1,20,'0.0','0','0.0'); print $sandHeap->{dim};
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
package ca; use strict; our $instability=4; # Konstruktor sub new { my $class = shift; my $self = {}; my @neighbourCells = {}; bless ($self, $class); foreach (qw/n iniTime finTime rndInit useNorth useDiagnoal/ ){ $self->set($_ => shift); } $self->set(neighbourCells => [@neighbourCells]); $self->addCells(); $self->addCellsNeighbors(); return $self; } # Methoden um Zellen zur Liste, und NachbarZellen der Zellen hinzuzufügen sub addCells{ my $self = shift; my $rnd=0; my $i=0; for($i=1; $i<=($self->{dim})*($self->{dim}); $i++){ if($self->{rndInit}){ $rnd = rand($ca::instability-1); } push($self->{cellList}, Cell->new($rnd)); } } sub addCellsNeighbors { my $self = shift; foreach($self->{cellList}) { $_->addNeighbors($self->{dim},$self->{useNorth},$self->{useDiagonal}); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
package cell; use ca; use strict; our $cellCount=0; #Konstruktor sub new { my $class = shift; my $self = {}; my @neighbourCells = {}; $cell::cellCount = $cell::cellCount + 1; my $index = $cell::cellCount; bless ($self, $class); foreach (qw/value/){ $self->set($_ => shift); } $self->set(valueAfter => 0); $self->set(index => shift); $self->set(neighbourCells => [@neighbourCells]); return $self; }
1
2
3
4
5
6
7
8
9
10
11
sub new {
my $class = shift;
my @values = @_; # den ganzen rest einlesen
my $self = bless({},$class);
$self->{'key'} = \@values;
}
# ... somewhere else
use Data::Dumper qw/Dumper/;
my $ca = CA->new(1,2,3);
print Dumper $ca->{key};
|< 1 2 >| | 17 Einträge, 2 Seiten |