You don't need all of those use constant N => 0; either -- the string literal is just as good as a constant.You haveI'm not clear on this :-)
and lateruse constant N => 0;
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.if ($dir == N) {return (--$r, $c)} elsif ... else { die "Inside 'step': invalid param\n" }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |