No no. return $map[$yCur-1][$xCur-1] eq $wall; is fine.

But, ouch. You're right about my simplification with grep, I looked far too briefly. Now let's see.. I always get confused by what conditions to use for grep in boolean context, so I'll think aloud.

!$cond1 and !$cond2 means that neither of them must be true. So the number of matches when testing for truth must be zero. That's not grep { $_ } $cond1, $cond2. So I was using the wrong one to begin with.

And I also overlooked that you weren't simply testing all coordinates for falseness - unraveled, it looks like this:

if ( ( !&test2($xCur, $yCur, $wall) && !&test3($xCur, $yCur, $wall) && &test5($xCur, $yCur, $wall) && &test6($xCur, $yCur, $wall) && !&test9($xCur, $yCur, $wall) ) && ( !&test1($xCur, $yCur, $wall) && !&test7($xCur, $yCur, $wall) ) || ( &test1($xCur, $yCur, $wall) && &test4($xCur, $yCur, $wall) && &test7($xCur, $yCur, $wall) && !&test8($xCur, $yCur, $wall) ) )
That looks decidedly more complex than a simple grep. But since the inner parens only contain &&s, the first two can be combined:
if ( ( !&test2($xCur, $yCur, $wall) && !&test3($xCur, $yCur, $wall) && &test5($xCur, $yCur, $wall) && &test6($xCur, $yCur, $wall) && !&test9($xCur, $yCur, $wall) && !&test1($xCur, $yCur, $wall) && !&test7($xCur, $yCur, $wall) ) || ( &test1($xCur, $yCur, $wall) && &test4($xCur, $yCur, $wall) && &test7($xCur, $yCur, $wall) && !&test8($xCur, $yCur, $wall) ) )
Now that looks almost like a datastructure, so let's make it one.
my %test1 = ( 2 => 0, 3 => 0, 5 => 1, 6 => 1, 9 => 0, 1 => 0, 7 => 0, ); my %test2 = ( 1 => 0, 4 => 0, 7 => 1, 8 => 0, );
Now we have good reason to modify the behaviour of the check_coordinates function: it isn't returning true/false, it's returning a comparison value. So have it return 0 if $lots_of_checks; and return 1 if $map[$y][$x] eq $wall;. Then we can rewrite that if as:
if( not(grep { check_coord($xCur, $yCur, $wall, $_) ne $test1{$_} } ke +ys %test1) or not(grep { check_coord($xCur, $yCur, $wall, $_) ne $test2{$_} } + keys %test2) ) { }
That looks bulky, but remember it's as bulky as it's going to get. If you need to add more conditions, you add them in the hashes, not the if. And rather than %test1 and %test2 you should use meaningful names - maybe %corner_pixels f.ex or some such, so your variables express your intent.

Makeshifts last the longest.


In reply to Re^3: large expression formating by Aristotle
in thread large expression formating by Dr.Altaica

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.