Just because you can do something with other tools, doesn't mean that you do it in Perl in the exact way. In fact, you can achieve the same result in a absolutely different way as shown by many monks above. While in some (very rare, IMO) circumtances it may be convenient to do what you intended, and it's truly prove of TMTOWTDI, but when we're talking about Real Code, turning arbitrary strings into distinct variables is just not the way. I personally think of it as an evil trap, would give much headache for me. They will clutter your code, after all.
Again, yes, you can do that in Perl. But, you can do it not because Perl encourages to do so. You can do it because the powerful way to do it (eval) is designed to do much more useful and flexible stuff, yet leads to disaster if used improperly. Don't you just realize that "eval" is only a byte away from "evil"? ;-)
As to solution for your Real Problem (assuming it's really about configuration parsing), I would prefer to search on CPAN for various Config packages.
Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.