in reply to (tedv)Re: Template system and substitution
in thread Template system and substitution

In the event that you did have nested tags, you would probably want to go for a recursive function. Something like:

sub parse { if ( $_[0] =~ /\[(.*)$/ ) { parse($1)} else { if ($_[0] =~ /(.*)\]/ ) { #Do your replace on $1 }else{ die "Unmatched brackets found"; } } }

or something like that anyway. But you probably wouldn't want nested brackets in a template system.

____________________
Jeremy

Replies are listed 'Best First'.
Re: Re: (tedv)Re: Template system and substitution
by extremely (Priest) on Nov 17, 2000 at 07:37 UTC
    But you probably wouldn't want nested brackets in a template system.
    I would =P

    UPDATE: Geez I was just trying to be goofy and now I have to justify this ;P

    OK, if you are just expressing basic values with your template system, you don't need nesting. If you are just enclosing code in another language you don't need nesting. If, however, you wish your template engine could do some light-weight decisions without having to resort to heavy code you might like having blocks like this:

    [? variable_that_might_exist ?] HTML that uses the array that [$ variable_that_might_exist $] flags the existence of... [@ maybe_array @] [/ variable_that_might_exist /]

    Worse, you may wish to emulate a light-weight version of a hash in template code like:

    [% hash_name -> [$ key_1 $] %]

    Sure it's stupid and there might be better ways but I have done something like it before (when I invented my own template system 4 years ago, where-o-where was Text::Template then?) and found that it was MUCH easier and safer to give my HTML people a seriously lightweight but "codeable" template system verses a glorified s/\[\$([a-zA-Z0-9_.-]+)\$\]/$hash{$1}/g system.

    Tho there is no shame in that system =)

    --
    $you = new YOU;
    honk() if $you->love(perl)