Don't ask to ask, just ask | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
If you add -w or use warnings to the top of your code you will get a whole heap of warning messages. Fixing these will get you a lot closer to seeing what is wrong with your code. A few hints: In your dec2bin sub, you are stripping leading zeros, but then relying upon having exactly 6 '1's or '0's when you later split the return value. Instead, us substr to return just the part of the string you want:
That will rid you of a couple of hundred runtime warnings. There are a couple of places where you are trying to test a value for being undef using:
That is much better done as
You are building your %range hash in a sub, but the hash is defined outside. Effectively a global which generally a frowned upon practice. The logic of your truth table is that values 8 .. 15, and 49, 51, 53, 55, 57, 59, 61, 63 are set to 1 and the rest 0. You may or may not see a way to use this information to do the initialisation in a better way? When iterating over a simple range of integers in Perl, it's generally considered more readable and easier to code that as:
but it's ultimately a personal preference thing. To select a random node you could use:
Again, you may see a better way to code that. In reply to Re: GP problem with tree structure using hash
by BrowserUk
|
|