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 }

In reply to Re: 36 Conditions in If Statement [sendhelp]] by FreeBeerReekingMonk
in thread 36 Conditions in If Statement [sendhelp]] by UpTide

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.