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

I first thought you could do the checks in a nested loop, but it turns out that you would essentially have to rewrite the loops that you used to populate the matrix, so that you wouldn't really check very much.

Just a quick comment on your loops. Using Perl-style loops instead of C-style loops might be slightly easier, for example:

for my $i (0..6) { for my $j (0..6) { $matrix[$i][$j][$_] = 0 for (0..2); } }

Replies are listed 'Best First'.
Re^2: 36 Conditions in If Statement [sendhelp]]
by UpTide (Novice) on Feb 04, 2017 at 10:48 UTC

    I have changed!
    using $_ for (0 .. 2) scares me though

      using $_ for (0 .. 2) scares me though

      Be not afraid! This is a bedrock Perl idiom. The  $_ variable is completely localized (update: and aliased! — it can be used to assign to the for-loop list item if that item is an lvalue) (I believe the term is "topicalized") within the for statement or statement block. Do you have any specific concern about this usage?


      Give a man a fish:  <%-{-{-{-<

        My fear, be it rational or not, is that $_ is very generic and I have no idea what it means when I look back over my code. With $i, $j, $k, $l, etc. I always use as indexes so I know that's an index; I try to name everything else as something meaningful. My example isn't well named but It's still easier for me to remember what I'm trying to do with $input, $output, @mask, rather than $_.

        When possible I try to assign and use something like $i instead of $_. Is this a bad habit?

      You don't need to use $_, I just wanted to show a possible alternative syntactical construct (statement modifier) for the most inner loop.