Re: Interpolate variable in a __DATA__ block
- From: noreply@xxxxxxxxx (Gunnar Hjalmarsson)
- Date: Sun, 30 Mar 2008 12:06:29 +0200
Trudge wrote:
On Mar 29, 4:05 pm, nore...@xxxxxxxxx (Gunnar Hjalmarsson) wrote:Trudge wrote:I'm trying to get a script to interpolate variable values in a
__DATA__ block if possible.
<snip>
It can be done; see the FAQ entry
perldoc -q "expand variables"
<snip>
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 :)
<snip>
As far as I know, templates require separate files to
work with. To avoid a lot of separate files, I've been using 'here'
documents up until now, all contained in one large script. But I
wondered if I could achieve a similar
effect putting the blocks of text in a __DATA__ block. Now I know it
can be done, so I will be exploring this method.
Not much to explore, really. Did you read the applicable Perl FAQ? Even if it provides this method, it doesn't exactly recommend it... Besides full-blown template methods, the FAQ suggests a couple of other methods, that usually are better, and so is here documents which you say you have been using.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.
- Follow-Ups:
- Re: Interpolate variable in a __DATA__ block
- From: aneely
- Re: Interpolate variable in a __DATA__ block
- References:
- Interpolate variable in a __DATA__ block
- From: Trudge
- Re: Interpolate variable in a __DATA__ block
- From: Gunnar Hjalmarsson
- Re: Interpolate variable in a __DATA__ block
- From: Trudge
- Interpolate variable in a __DATA__ block
- Prev by Date: opening sftp command as a file
- Next by Date: Re: Automate a search query from a website
- Previous by thread: Re: Interpolate variable in a __DATA__ block
- Next by thread: Re: Interpolate variable in a __DATA__ block
- Index(es):