in reply to 36 Conditions in If Statement [sendhelp]]
Hello UpTide,
Here’s an approach which, although less efficient, is easier to read and therefore to debug:
use strict; use warnings; use List::Util qw( all ); ... # create and populate my @matrix as before ... my @indices = ( [0, 4, 0], [0, 4, 1], [0, 4, 2], [1, 4, 0], [1, 4, 1], [1, 4, 2], [2, 4, 0], [2, 4, 1], [2, 4, 2], [4, 4, 0], [4, 4, 1], [4, 4, 2], # A [5, 4, 0], [5, 4, 1], [5, 4, 2], [6, 4, 0], [6, 4, 1], [6, 4, 2], [4, 0, 0], [4, 0, 1], [4, 0, 2], [4, 1, 0], [4, 1, 1], [4, 1, 2], [4, 2, 0], [4, 2, 1], [4, 2, 2], [4, 4, 0], [4, 4, 1], [4, 4, 2], # B [4, 5, 0], [4, 5, 1], [4, 5, 2], [4, 6, 0], [4, 6, 1], [4, 6, 2], ); my @to_test; push @to_test, $matrix[ $_->[0] ][ $_->[1] ][ $_->[2] ] for @indices; print "It worked\n" if all { $_ == 1 } @to_test;
By making it easier to see which array elements are being tested, this approach reveals that three of the tests are in fact duplicated (see the lines labelled A and B).
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: 36 Conditions in If Statement [sendhelp]
by AnomalousMonk (Archbishop) on Feb 04, 2017 at 17:58 UTC |