On Mar 29, 4:05 pm, [EMAIL PROTECTED] (Gunnar Hjalmarsson) wrote:
> Trudge wrote:
> > 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.
>
> It can be done; see the FAQ entry
>
>      perldoc -q "expand variables"
>
> <snip>
>
> >    while (<DATA>)
> >    {
> >            chomp;
> >            if ($_ eq "<$data>")
> >            {
> >                    next;
> >                    print "$_\n";
> >            }
> >            if ($_ eq "</$data>")
> >            {
> >                    last;
> >            }
> >            print "$_\n";
> >    }
>
> Try to replace that with:
>
>         while (<DATA>) {
>                 chomp;
>                 next if $_ eq "<$data>";
>                 last if $_ eq "</$data>";
>                 s/(\$\$\w+)/$1/eeg;
>                 print "$_\n";
>         }
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl

Gunnar, this works perfectly, and is what I am trying to achieve. Many
thanks, and a brew on me :)

For the curious, I find myself sometimes having to display similar
blocks of text over and over, with only minor changes. It could be
HTML or XML. 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.

Thanks to all who responded.
--


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


Reply via email to