#!/usr/bin/perl use warnings; use strict; package Getraenkeautomat { sub new { my $classname = shift; my $self = {bottles_of_cola => 10}; return bless($self, $classname); } sub gibMirEineCola { my $self = shift; if ($self->{bottles_of_cola} > 0) { print "Bitteschoen!\n"; $self->{bottles_of_cola}--; print "Noch $self->{bottles_of_cola} Flaschen Cola uebrig.\n"; } } } package Man { sub new { my $classname = shift; my $self = {thirst => 0}; return bless($self, $classname); } sub sweat { my $self = shift; my $getraenkeautomat = shift; print "Ganz schoene Hitze, ich werde durstiger.\n"; $self->{thirst}++; if ($self->{thirst} > 1) { print "Ich brauche eine Cola!\n"; $getraenkeautomat->gibMirEineCola(); } } } my $getraenkeautomat = Getraenkeautomat->new(); my $user = Man->new(); $user->sweat($getraenkeautomat); $user->sweat($getraenkeautomat);