"Michael C. Davis" wrote: > Hi, Apologies if I'm bringing up a repeated topic. I searched the list > archive and the web and nothing specific has turned up so far. > > Is there a way to defer evaluation of the contents of a here-doc-defined > value such that one can embed variables in the here-doc and not have them > evaluated until they are used later? Something like this:
It looks like you have gotten some good pointers to how you can accomplish this. I would suggest that you give some thought to whether it is a good idea to try this. What do you hope to accomplish by doing this? If you simply don't want to have the heredoc someplace where it interferes wh the flow of code, there is a much better, much less obfusciated way. > > > code: > ----- > use strict; > use warnings; > > my $header = <<'end_of_header'; > # File: $filename > end_of_header > > my $filename = 'xyz'; > print $header, "\n"; # output: want to see # File: xyz, but get # File: > $filename I am not sure how the above is any more clear than it would be if you assigned a value to $filename first. > > > I tried a few variations and nothing seems to work, as shown below. (This > RFC http://dev.perl.org/perl6/rfc/229.html from Perl 6 implies that there > is fact no way to do this.) Can anyone clarify. Thank you. How about this: Greetings! E:\d_drive\perlStuff>perl -w use strict; use warnings; sub file_report_line { my $filename = shift; return <<END_STRING; # File: $filename END_STRING } my $filename = 'xyz'; print file_report_line($filename), "\n" ^Z # File: xyz Of course, the above code is rather senseless anyway, since it could be much more clearly written: return "File: $filename"; without all the baggage, but I am assuming that there is a bit more substance to your real heredoc. I still can't see a good reason for putting that low-level implementation detail at the top of the script, but this approach should work. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>