Re: Interpolate variable in a __DATA__ block



"T" == Trudge <trudge@xxxxxxxxx> writes:

T> On Mar 30, 8:13 am, chas.ow...@xxxxxxxxx (Chas. Owens) wrote:
>> On Sat, Mar 29, 2008 at 9:14 PM, Trudge <tru...@xxxxxxxxx> wrote:
>>
>> > > Try to replace that with:
>>
>> > > while (<DATA>) {
>> > > chomp;
>> > > next if $_ eq "<$data>";
>> > > last if $_ eq "</$data>";
>> > > s/(\$\$\w+)/$1/eeg;
>> > > print "$_\n";
>> > > }
>> > Gunnar, this works perfectly, and is what I am trying to achieve. Many
>> > thanks, and a brew on me :)
>>
T> use Inline::Files;

T> print while <FOO>;
T> print while <BAR>;
T> print while <BAZ>;

T> my $foo="FOO";
T> my $fooRef=\$foo;

T> my $bar="BAR";
T> my $barRef=\$bar;

T> my $baz="BAZ";
T> my $bazRef=\$baz;

T> __FOO__
T> This is $foo
T> This is still $$fooRef
T> __BAR__
T> This is $bar
T> This is still $$barRef
T> __BAZ__
T> This is $baz
T> This is still $$bazRef

why would you think Inline::Files would do interpolation for you when
DATA doesn't?? all that gives you is MORE DATA blocks with their own
handles. it is still plain text data and they don't do templating on
their own. you still need the /eeg trick to do that.

and as i said, you are going down a very bad path. the /eeg trick is
limited to only expanding variables you have declared. it is a pain to
extend and manage and you will end up reinventing all the other template
tricks you need. use a template module (i mentioned mine since it is
easy to learn and use). you have been warned!

uri

--
Uri Guttman ------ uri@xxxxxxxxxxxxxxx -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
.



Relevant Pages