Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: 36 Conditions in If Statement [sendhelp]]

by FreeBeerReekingMonk (Deacon)
on Feb 04, 2017 at 19:44 UTC ( [id://1181108]=note: print w/replies, xml ) Need Help??


in reply to 36 Conditions in If Statement [sendhelp]]

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 }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1181108]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-24 06:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found