|No such thing as a small change|
Initialize constant with scalarby ait (Friar)
|on Aug 17, 2012 at 17:11 UTC||Need Help??|
ait has asked for the
wisdom of the Perl Monks concerning the following question:
I found a much more elegant solution. I guess all in our team were all just too tired to see it. Anyway hope it will help someone in the future. The reason I prefer to use the here-to quoting (in favor of something like q ) is because it seems likely that there could be problems with the character used for opening and closing any other quoting method, as this character could appear in the quoted text as well.
I found a node here 843110 that talks about this but the OP wanted something that was only available at runtime which is not what constants are for, IMHO.
Anyway, I'm lokking for the same thing but to store some XML templates in a lib. And the only way we have got it to work is by using the scalar ref (as they are allowed and documented in the constant pod), like this:
My question is twofold. Firstly, I'm guessing this is not the best way because the value of the reference could be changed (not a real a concern in our implementation). Second, are the other or better ways to accomplish this? Answering myself here and I could probably use q() but I wanted to avoid problems with any formatting (e.g. a linefeed before the xml declaration, etc.) the open seemed more elegant. Anyway, seeking opinions!