use 5.010_001; use strict; use warnings; use diagnostics; my $diagnosticsenabled; BEGIN { $diagnosticsenabled = 0; eval { use diagnostics; $diagnosticsenabled = 1; }; } if(!$diagnosticsenabled) { print "'use diagnostics' is not available, you will not get detailed error messages.\n"; } else { print "diagnostics module loaded!\n"; } #### package Array::Contains; use 5.010_001; use strict; use warnings; our $VERSION = 2.8; use Carp; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(contains); sub contains { my ($value, $dataset) = @_; if(!defined($value)) { croak('value is not defined in contains()'); } if(!defined($dataset)) { croak('dataset is not defined in contains()'); } if(ref($value) ne '') { croak('value is not a scalar in contains()'); } if(ref($dataset) ne 'ARRAY') { croak('dataset is not an array reference in contains()'); } foreach my $key (@{$dataset}) { next if(ref($key) ne ''); if($value eq $key) { return 1; } } return 0; } #### package Array::Contains; use 5.010_001; use strict; use warnings; our $VERSION = 2.8; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(contains); sub contains { my ($value, $dataset) = @_; foreach my $key (@{$dataset}) { next if(ref($key) ne ''); if($value eq $key) { return 1; } } return 0; }