I looked for you in the
Math::Matrix module, but the lack of splice()-like functions (only selecting columns is possible) makes it impossible to use that.
So here is my attempt at testing a range of values:
so you have a range of numbers:
range => "0..2,4..6;4;0..2",
Which means X=0,1,2,4,5,6 and Y=4 and Z=0,1,2
Then you can set the *value*. The value passes through an eval block (very slow) but it allows "math":
value => '$x+$y'
in the example, we only use the value "1":
use warnings;
use strict;
#fancy matrix
my @matrix;
#set to a blank 3d test matrix 7x7x3
for my $i (0 .. 6) {
for my $j (0 .. 6) {
for my $k (0 .. 2) {
$matrix[$i][$j][$k] = 0;
}
}
}
#set some values for matrix
for my $j (0..2, 4..6) {
my $i = 4;
for my $k (0 .. 2) {
$matrix[$i][$j][$k] = 1;
}
}
for my $i (0..2, 4..6) {
my $j = 4;
for my $k (0 .. 2) {
$matrix[$i][$j][$k] = 1;
}
}
my $test1 = testrange( {
range => "0..2,4..6;4;0..2",
value => 1,
matrix=>\@matrix
} );
my $test2 = testrange( {
range => "4;0..2,4..6;0..2",
value => 1,
matrix=>\@matrix
} );
if($test1 && $test2 ){
print "it worked";
}else{
print "it did not work";
}
sub testrange{
my($d)=@_;
my ($XX,$YY,$ZZ) = split(/\s*;\s*/, $d->{range});
my @X = eval($XX);
my @Y = eval($YY);
my @Z = eval($ZZ);
my $M = $d->{matrix};
my $success = 1;
for my $x (@X){
for my $y (@Y){
for my $z (@Z){
my $value = eval($d->{value});
#print "DEBUG test:[$x,$y,$z]=$value == $M->[$x][$y][$
+z]\n";
unless($value eq $M->[$x][$y][$z]){
print "FAIL test:[$x,$y,$z]=$value != $M->[$x][$y]
+[$z]\n";
$success = 0;
#return 0; # fail immediately
}
}
}
}
return $success; # sucess
}