package My::Queue; use strict; use warnings; sub new { my $class = shift; my $size = shift || 7; my $self = {}; $self->{'size'} = $size; $self->{'queue'} = [ ]; $#{$self->{'queue'}} = $size-1; bless $self, $class; return $self; } sub put { my $self = shift; my @values = @_; unshift @{$self->{'queue'}},@values; $#{$self->{'queue'}} = $self->{'size'}-1; return scalar @values; } sub get { my $self = shift; my $index = shift; die ('Queue: Index out of bounds') if ($index < 0 or $index > $self->{'size'}-1); return $self->{'queue'}->[$index]; } package main; use strict; use warnings; my $q = My::Queue->new; $q->put(1,2,3); print "Nummer 0: " . $q->get(0) . "\n"; print "Nummer 2: " . $q->get(2) . "\n"; #print "Nummer 3: " . $q->get(3) . "\n"; # wirft ein die! #print "Nummer -9: " . $q->get(-9) . "\n"; # wirft ein die! $q->put(99,88,77,66,55); 1;