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: 
> 
        When you need to do something like that, I give them names like: <myfilename>

        Then do a $header =~ s/<myfilename>/$filename/gi;  at the point you want to do 
the print.
        Now if doing more than once, then would wnat to put into secondardy variable 
to do the changes.


>     code:
>     -----
>     use strict;
>     use warnings;
> 
>     my $header = <<'end_of_header';
>     # File: $filename
        #File: <myfilename>

>     end_of_header
> 
>     my $filename = 'xyz';
 $header =~ s/<myfilename>/$filename/gi;
>     print $header, "\n"; # output: want to see # File: xyz, but get #
> File: $filename

        The reason you are getting $filename in this instance has to do with using 
single ' vs double ". If double had been used then  you would have had:
        File: 

Wags ;)
> 
> 
> 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. 
> 
>     code:
>     -----
>     use strict;
>     use warnings;
> 
>     my $header = <<'end_of_header';
>     # File: $filename
>     end_of_header
> 
>     my $filename = "test";
> 
>     print $header, "\n";
>     print eval { "$header" }, "\n";
>     print "$header", "\n";
> 
>     print eval { $header }, "\n";
>     print ((eval $header) ."\n");
> 
>     output [ .. editted for readability .. ]:
>     -------
> 
>     # File: $filename
>     # File: $filename
>     # File: $filename
>     # File: $filename
>     Use of uninitialized value in concatenation (.) or string at
> ..\perlt\testevalsimple.pl line 15.



      Any questions and/or problems, please let me know.

      Thanks.

Wags ;)
Int: 9-8-002-2224
Ext: 408-323-4225x2224



**********************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
****************************************************************


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to