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,


In reply to Re: 36 Conditions in If Statement [sendhelp] by Athanasius
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.