Interpolate variable in a __DATA__ block
- From: trudge@xxxxxxxxx (Trudge)
- Date: Sat, 29 Mar 2008 12:05:42 -0700 (PDT)
I'm trying to get a script to interpolate variable values in a
__DATA__ block if possible. This is a kind of alternative to a full-
blown template method. I'm not sure if I can even do what I want,
hence my posting here. The following code only goes so far. It
correctly prints the value of $$dataref each time GetData is called,
but not in the while loop. This is where I'm stuck.
8<---------------------
#! /usr/bin/perl
use strict;
use warnings;
my @Blocks=qw(first second third);
foreach my $block (@Blocks)
{
GetData($block);
}
sub GetData
{
my $data=shift;
my $dataref=\$data;
print "\$\$dataref is: $$dataref\n";
while (<DATA>)
{
chomp;
if ($_ eq "<$data>")
{
next;
print "$_\n";
}
if ($_ eq "</$data>")
{
last;
}
print "$_\n";
}
}
__DATA__
<first>
This is the $$dataref chunk.
</first>
<second>
This is the $$dataref chunk.
</second>
<third>
This is the $$dataref chunk.
</third>
8<------------------------
.
- Follow-Ups:
- Re: Interpolate variable in a __DATA__ block
- From: John W. Krahn
- Re: Interpolate variable in a __DATA__ block
- From: Gunnar Hjalmarsson
- Re: Interpolate variable in a __DATA__ block
- From: Rob Dixon
- Re: Interpolate variable in a __DATA__ block
- Prev by Date: sort without ignoring hyphens
- Next by Date: Re: diff says memory exhausted need help with perl
- Previous by thread: sort without ignoring hyphens
- Next by thread: Re: Interpolate variable in a __DATA__ block
- Index(es):