|
|
| "be consistent" | |
| PerlMonks |
Storing multiple blocks of text in the __DATA__ sectionby blindluke (Hermit) |
| on Jan 02, 2015 at 12:48 UTC ( [id://1111993]=perlquestion: print w/replies, xml ) | Need Help?? |
|
blindluke has asked for the wisdom of the Perl Monks concerning the following question: Enlightened Monks! I'm storing a few descriptions within the code. Right now, it's done in a very basic way:
Honestly, I don't like it. I would much rather see it in the DATA section (and later in a file of its own), with the following (or similar) layout:
Does anyone know of a Config:: module that would accept such syntax? Or a way to put something like multiple __DATA__ sections in the code, each with a name of their own? I could parse such a section myself, with something like this:
... but it seems worse than the initial solution, with direct assignments to the hash keys. Still, maybe there is a more elegant way to parse such a DATA section. UPDATE:Can I use split with a regexp pattern, and use a capture within the pattern, to get the hash key? I managed to find the answer to this one. The code below produces the desired %desc hash. But the grep/split combo looks only marginally better than the loop example above.
- Luke
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||