P is for Practical | |
PerlMonks |
Re^2: Uninitialized warnings troubleby hv (Prior) |
on Dec 14, 2022 at 06:08 UTC ( [id://11148854]=note: print w/replies, xml ) | Need Help?? |
Excellent, well done. :) I see you are already writing quite different code from what you started with. Next it might be worth thinking about whether you can rearrange things to avoid having to repeat this block over and over:
Note also that you don't need syswrite STDOUT here, print is quite enough - you just need to set $| = 1; at the start to disable buffering. For what it's worth, here is my version which uses almost the same approach:
If the speed of this algorithm ever becomes an issue, it also becomes interesting to consider a more dynamic approach: with a companion array of "visible/invisible" booleans, you can make just two passes over each row (once in each direction, or combined) and two over each column, then read the result out of the companion array. That reduces the algorithmic complexity from O(n^3) to O(n^2) for an n * n array.
In Section
Seekers of Perl Wisdom
|
|