1.6: Tips When Generating Code
- Use here docs so you can see the code most clearly
- No extra quotes, newlines
- Indenting you can easily control
- Generate parts separately
- Build lists of parts if needed
- Integrate parts with full sub here doc
- These can be done in subs if complex
- Use .= to build up code (a great and underused op)
- Nested indents need to be recursive and tracked with an $indent var
- Use Data::Dumper to generate clean strings
- Generate subs for later execution
- Don't eval code to execute immediately
- Give access to generated code
- Very useful for debugging
- Also for testing and optimization
- Users can cut/paste code and bypass generation and module loading