You don't need all of those use constant N => 0; either -- the string literal is just as good as a constant.
I'm not clear on this :-)
You have
use constant N => 0;
and later
if ($dir == N) {return (--$r, $c)} elsif ... else { die "Inside 'step': invalid param\n" }
use constant... essentially gives you a subroutine-ish entity (without a sigil). If you miss the constant declaration, you'll be looking for a subroutine definition for N, NE,, etc. Still, some people like this.

The benefits of declaring these constants are:
• difficult to accidentally reassign to constants
• direction validation (with die...)
• saving quotes in comparison (as in  if ( $dir eq "N" ))
[Assuming that $dir is now a string.]

The drawbacks are:
• no obvious sub definition
constant isn't perfectly constant
• constants aren't interpolated in double quoted strings
[See use constant for a complete rundown.]

I guess what I'm really saying is that it's unfair to compare a literal translation between C and Perl. Each have their idiosynchracies, and will fall short of the "ideal" on some scales.

Someone here could probably write up a Perlish version of this that was easier to follow, easier to maintain, and perhaps did a few nifty tricks to boot. Though it might run slower than C. :)

-QM
--
Quantum Mechanics: The dreams stuff is made of


In reply to Re: Re: Re: Word Search Puzzle by QM
in thread Word Search Puzzle by Anonymous Monk

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.