in reply to Re: Why is this string only PARTIALLY interpolated?
in thread Why is this string only PARTIALLY interpolated?

Can you help me understand what you mean by "a proper template system" and how to implement it in MYSQL? I know what a template is, not sure I'm familiar with the set of "proper" ones. TY
  • Comment on Re^2: Why is this string only PARTIALLY interpolated?

Replies are listed 'Best First'.
Re^3: Why is this string only PARTIALLY interpolated?
by hippo (Archbishop) on Aug 04, 2023 at 15:47 UTC
    #!/usr/bin/env perl use strict; use warnings; use Template; my $from_db = q/Oh this year I'm off to Sunny [% country %]! /; my $tmpl = Template->new; for my $dest (qw/Greece Italy Spain/) { $tmpl->process (\$from_db, { country => $dest }); }

    $from_db is the immutable thing (the template) which you store in and retrieve from the DB. We then use Template to perform the required modifications. Template is one of the "proper" ones as you can find it listed in Task::Kensho. There are others, of course.


    🦛

      interesting. TY I did not know about template TY for the advice and education.
Re^3: Why is this string only PARTIALLY interpolated?
by ikegami (Patriarch) on Aug 05, 2023 at 06:05 UTC

    You're processing the template in Perl, not MySQL. Template-Toolkit is my go-to template system. The template would look like

    [% cat.dog %]/mouse
    instead of
    $cat->{dog}/mouse
      interesting TY, studying this solution. I've never heard of this before (after LAMP programming since 1996!) or heard it ever mentioned in any of myriad OSCONs I've attended. A nice surprise!

        Template toolkitz is also extendable, e.g. you can write your own plugins. Most of my websites support* multi-language, i just enclose any text to be translated in [% tr.trquote("Hello World") %]

        * = in theory. The webserver supports it. My own laziness guarantees that at least my private websites don't have proper translations available.

        PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP