sub RemoveSheep { my $self = shift; my $obj = shift; # This is the sheep object my $field = ${$self->{field}}; my @sheep = @{$field->Sheep}; my $index = 0; my $found = undef; foreach my $sheep (@sheep) { if( $sheep == $obj ) { $found = $index; last; } $index++; } if( defined($found) ) { my $sheep = $sheep[$found]; print "Before Splice: " . @sheep . "\n"; splice (@sheep, $found, 1); print "After Splice: " . @sheep . "\n"; } } #### #!/usr/bin/perl -w use strict; use Sheep; use Shepherd; use Field; my $fieldWidth = 500; my $fieldHeight = 500; my @sheep = (); for(my $i = 0; $i < 100; ++$i) { my $randX = sprintf( "%d", rand($fieldWidth)); my $randY = sprintf( "%d", rand($fieldHeight)); my $sheep = new Sheep($randX, $randY); push(@sheep, $sheep); } print "Address of array is: " . \@sheep . "\n"; print "Shepherd now looking for " . @sheep . " sheep\n"; my $field = new Field( $fieldWidth, $fieldHeight, \@sheep); print "Shepherd starting at: 200:300\n"; my $shepherd = new Shepherd(\$field, 200, 300); $shepherd->FindSheep();