sub is_empty_list { return @{$_[0]} == 0; } # remove ($what, $list, $howmany) # # Removes $what from the list $list up to $howmany times. # If $howmany is not provided, removes all occurrences of $what. # sub remove { my $what = $_[0]; my $list = $_[1]; my $howmany = defined $_[2] ? $_[2] : -1; my @ret = (); foreach my $elem (@{$list}) { push @ret, $elem unless ($elem == $what and $howmany-- > 0); } return \@ret; }