#!/usr/bin/perl use strict; use warnings; package Person; use Moose; use constant DURATION => 100; has use_duration => ( isa => 'Int', is => 'ro', default => 1); has frequency => ( isa => 'Int', is => 'ro', default => 50 ); has population => ( handles => {obtain => 'push', release => 'shift', inventory => 'count', find => 'first_index', purge => 'delete'}, isa => 'ArrayRef[Person]', default => sub{ [] }, traits => ['Array'], is => 'ro', ); has number => ( isa => 'Int', is => 'rw', default => 0); sub need_to_go { my $self = shift; return ( rand(DURATION)+1 <= $self->frequency) ? 1 : 0; } no Moose; package main; use Data::Dumper; my $people_nr = 25; my $people = Person->new; for my $case ( 1 .. $people_nr ) { my $per = Person->new; $per->number( $case ); $people->obtain( $per ); } for my $p ( @{ $people->population } ) { if ($p->need_to_go) { # My problem is here. # I suppose to use # first_index( sub { ... }) method # and then delete or splice # but I cannot figure out what to feed # the sub { ... } with } } print Dumper $people;