#!/usr/bin/perl use warnings; use strict; package Konto; sub new { my $classname = shift; my $nummer = shift; my $name = shift; my $self = {nummer => $nummer, name => $name, sollsum => 0, habensum => 0, buchungen => [], saldo => 0, saldoisin => ""}; return bless($self, $classname); } sub bucheSoll { my $self = shift; my $soll = shift; my $bsatz = shift; $self->{sollsum} += $soll; push(@{$self->{buchungen}}, $bsatz); } sub bucheHaben { my $self = shift; my $haben = shift; my $bsatz = shift; $self->{habensum} += $haben; push(@{$self->{buchungen}}, $bsatz); } sub calcSaldo { my $self = shift; if ($self->{sollsum} > $self->{habensum}) { $self->{saldo} = $self->{sollsum} - $self->{habensum}; $self->{saldoisin} = "soll"; } elsif ($self->{sollsum} < $self->{habensum}) { $self->{saldo} = $self->{habensum} - $self->{sollsum}; $self->{saldoisin} = "haben"; } else { $self->{saldo} = 0; $self->{saldoisin} = "0"; } } sub clear { my $self = shift; $self->{sollsum} = 0; $self->{habensum} = 0; $self->{buchungen} = []; $self->{saldo} = 0; $self->{saldoisin} = ""; } package main; my $bankkonto = Konto -> new(1200, "Bank"); $bankkonto -> bucheHaben(13.36, "01.03.2011;X123;Telefonkosten;13,36;4920;1200"); $bankkonto -> bucheHaben(2.54, "01.03.2011;X123;VSt. Telefonkosten;2,54;1577;1200"); $bankkonto -> calcSaldo(); print "Saldo: $bankkonto->{saldo}\n"; print "Soll oder Haben: $bankkonto->{saldoisin}\n";