http://www.perlmonks.org?node_id=988033

ait has asked for the wisdom of the Perl Monks concerning the following question:

Update:

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.

@EXPORT= qw( XML_FOO XML_BAR ); use constant XML_FOO => <<FOO; #XML CODE HERE FOO use constant XML_BAR => <<BAR; #XML CODE HERE BAR # and so on... # Later in the implementation: $parser->parse_string(XML_FOO);

Original Post

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:

@EXPORT= qw( XML_FOO XML_BAR ); open my $foo, '<', \<<FOO; #XML CODE HERE FOO use constant XML_FOO => \$foo; open my $bar, '<', \<<BAR; #XML CODE HERE BAR use constant XML_BAR => \$bar; # and so on... # Later in the implementation: $parser->parse_string(${XML_FOO()});

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!

Thanks,
Alejandro Imass

</code>