Sharan, Personaly would make use of a hash variable where the templates are named by the key and the actual template is the value. This will give you the option to add more templates as and where needed.
With a little time and effort more complex templates can be created if you expand upon the basic hash and define a more complex datastructure. In the end you can make it as simple or complex as you want without having to worry about all kinds of loopholes to get around the on datasection restriction in perl. Now of course if all you need is flat text why not use the __DATA__ section but from your question I understand that there is more needed then just flat text. Regards, Rob. On 2/7/07, Sharan Basappa <[EMAIL PROTECTED]> wrote:
Hi Rob, Actually I am writing a script that actually spits out various make template files. People then fill in these templates with neccessary details and use them. The thing is that there are atleast 4-5 different templates and depending on the cmd line arg, the script needs to output one of these template files. Definitely I would not like to open a file, read it and then output it since moving the script (to another project etc) would mean that the files need to be moved too. Having this information in the same script would make it self contained. Does that make sense... Thanks .. On 2/7/07, Rob Dixon <[EMAIL PROTECTED]> wrote: > > Sharan Basappa wrote: > > > > On 2/6/07, Tom Phoenix <[EMAIL PROTECTED]> wrote: > >> > >> On 2/6/07, Sharan Basappa <[EMAIL PROTECTED]> wrote: > >> > >>> Question is how to embed text in a perl program instead of reading it > >>> from a file or initializing the text in a string variable. > >> > >> Are you looking for here-documents? Look in perlop under Quote and > >> Quote-like Operators to see the different ways of putting text data > >> into your program. > >> > >>> Another question is whether perl will replace the variable defined in > the > >>> embedded text with actual values ? > >> > >> Do you mean double-quote interpolation? Here-docs normally > >> interpolate, but you can disable that (akin to single-quoting instead > >> of double-quoting). > >> > >> > while (<MY_BLOCK>) > >> > >> > __MY_BLOCK__ > >> > >> It looks as if you've seen the special DATA filehandle and the > >> __DATA__ marker; but those don't generalize like that. Nice try, > >> though. (If you change those back to DATA in your program, I think it > >> will do what you expected. Consider adding 'use strict' and 'use > >> warnings', though.) > > > > What if I wanted to have multiple embedded (and separate) texts embedded > in > > my program. Are you saying that I can have only one text section and > that > > should have keyword DATA. Actually when I wrote example, I assumed that > > double underscore tell the parser that a text section starts (so used my > own > > name - my_block) > > What the DATA filehandle does is to allow the Perl program to read from > its own > source file. The read position is set initially to the point after the end > of > the program marked by the __END__ tag (as a mnemonic the __DATA__ tag > serves the > same purpose). Since a program has only one source file there can be only > one > such magic filehandle. (As a point of interest, it's possible for a > program to > read its own source by issuing "seek DATA, 0, 0" before reading from the > handle.) > > It's clearly possible to add markers within the data so the the program > can > split it up itself, but how about explaining a little more about what you > want > to do: I'm sure the list can come up with an appropriate solution for you. > What > is wrong, for instance, with using real separate data files? > > HTH, > > Rob >