Think about Loose Coupling | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
When you get some incomprehensible code, I'd suggest first running it through perltidy to get a better feel for what it looks like. You can then put in a few print statements to see what the values are initialized to. When I did so, I got this:
After we run the code, we can see that it sets @t to (2, 3, 0) and @x to (1, 7, 3). If you had real code (instead of this obfuscated nonsense), you could analyze the functions map is applying to the incoming lists for initializing the @t and @x variables. I'd just edit the code and set @t and @x with the final values. After cleaning up the variable initializations, I'd then start looking for ways to simplify the various bits of code. For example, $i and $five are nearly unused--$five is used only once in a print statement, $i is used once in an expression and once in a print statement. So I'd delete those two variables and replace their uses with the corresponding values (4 for $i and 7 for $five). Variable deletion isn't always something I suggest, but sometimes it's the right tool. Next, I'd take advantage of any obvious algebraic simplifications, such as ( 4 / 2 ) with 2 and ( @x[0] * 2 * 2 / 2 ) with ( @x[0] * 2 ) and also replace constant function calls (such as the ones to chr()) with the results. Note: You can do a quick command-line experiment to find out the values from constant function calls, like this:
After doing this, and removing the now unnecessary print statements, I got:
From here, you could even replace all the references to @t and @x with their values, simplify further and boil the code down to:
...roboticus When your only tool is a hammer, all problems look like your thumb. In reply to Re: Map coordinates?
by roboticus
|
|