Andy Wardley wrote:
> On Thu, Nov 22, 2001 at 08:08:19PM +0100, Frank Herrmann wrote:
>
>>[% var = ['first','next'];
>> text = "The Text";
>> .... progging ...
>> text = "${text} is ${var.0} and then ${var.1}!";
>> # ... ^^^^^^ this is very ugly ;-)
>>%]
>>
>
> How about this for concatenation:
>
> [% text = BLOCK %]
> The text is [% var.0 %] and then [% var.1 %]
> [% END %]
that's ala document here, which is nice for a few blocks, but too long
if you need to do many concats. I believe there should be something that
helps us to build strings in one line and still have them readable.
${foo.bar.zed} is definitely not readable if there are many
interpolations mixed with other plain strings.
> or this for something like sprintf():
>
> [% USE format("%s is %s and then %s") %]
> [% format(text, var.0, var.1) %]
If you need many concats with different number of arguments that's too
cumbersome. If you look at it again, it's always %s, so why not to have
a generic core concat() function, which simply does join("", @_). e.g.:
[% text.concat("The text is ", var.0, " and then ", var.1) %]
Alternatively if we want to find a replacement for perl's . or other
languages + concat operators, how about c++ streams?
doing the join("", @_) manually is not maintainer/developer friendly.
This should be done in-core and very easy to do by defining a simple
scalar operator.
[% text = "The text is " << var.0 << " and then " << var.1 << endf; %]
with '<< endl' being magical var standing for end of line (which is
cool, since for different OSs, this can be transparantely set to be
"\n", "\r" or "\r\n".
since we neither can use the .= construct which sucks, we can have < and
<< ala open()'s > (overwrite) and >> (append) but the other way around.
[% text < "The text is " << var.0;
text << " and then ";
text << var.1 << endf;
%]
so now you can append to your vars and have the templates readable and
maintainable. You have to agree that this:
[% text = "$text some appendix"; %]
is an ugly and cumbersome way to say:
$text .= "some appendix";
if you rather like my first suggestion with the core concat() function,
the append() function is due as well:
[% text.concat("The text is ", var.0);
text.append(" and then ", var.1, "\n");
%]
and to complete the suite, how about prepand().
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:[EMAIL PROTECTED] http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/