use strict;
use warnings;
my( @p_types ) = qw/ pam php kph /;
my( @c_types ) = qw/ cam c1 c2 /;
my @true = qw/ pam c2 /;
my @false = qw/ cam c2 /;
my %p_hash;
@p_hash{@p_types} = ();
my %c_hash;
@c_hash{@c_types} = ();
print "\@true is ",
( qualify( \@true, \%p_hash, \%c_hash ) )
? "True.\n"
: "False.\n";
print "\@false is ",
( qualify( \@false, \%p_hash, \%c_hash) )
? "True.\n"
: "False.\n";
sub qualify {
my( $test_aref, $p_href, $c_href ) = @_;
if(
grep{ exists $p_href->{$_} } @{$test_aref} and
grep{ exists $c_href->{$_} } @{$test_aref}
) {
return 1;
} else {
return 0;
}
}
####
package All_In;
use strict;
use warnings;
sub new {
my $class = shift;
my( $p_types, $c_types ) = @_;
my( %p_hash, %c_hash );
@p_hash{ @{$p_types} } = ();
@c_hash{ @{$c_types} } = ();
my $self = {};
$self->{p_hash} = \%p_hash;
$self->{c_hash} = \%c_hash;
bless $self, $class;
}
sub qualify {
my( $self, @target ) = @_;
if(
grep{ exists $self->{p_hash}{$_} } @target
and grep{ exists $self->{c_hash}{$_} } @target
){
return 1;
} else {
return 0;
}
}
1;
package main;
use strict;
use warnings;
my $sets = All_In->new(
[ qw/ pam php kph / ],
[ qw/ cam c1 c2 / ]
);
my @true = qw/ pam c2 /;
my @false = qw/ cam c2 /;
print "\@true is ",
$sets->qualify( @true )
? "True.\n"
: "False.\n";
print "\@false is ",
$sets->qualify( @false )
? "True.\n"
: "False.\n";
####
use strict;
use warnings;
use Quantum::Superpositions;
my @p_types = qw/ pam php kph /;
my @c_types = qw/ cam c1 c2 /;
my @true = qw/ pam c2 /;
my @false = qw/ cam c2 /;
print "\@true is ",
qualify( \@true, \@p_types, \@c_types )
? "True.\n"
: "False.\n";
print "\@false is ",
qualify( \@false, \@p_types, \@c_types )
? "True.\n"
: "False.\n";
sub qualify {
my( $target, $p_types, $c_types ) = @_;
my $quantum_target = any( @{$target} );
return 1 if (
$quantum_target eq any( @{$p_types} )
and $quantum_target eq any( @{$c_types} )
);
return 0;
}