Howdy, 

I'm using Template Toolkit 2.08 (very cool system) and 
I'd like to count the occurrences of a pattern in a string.
In Perl, I can do this a number of ways:

my @matches = ($str =~ /($pattern)/g);

or

my $matches = ($str =~ tr/$pat/$pat/);

I may have missed something in the docs, but 
I don't see a similar function in TT. The scalar
vmethod match() doesn't appear to use the /g modifier. 

In TT, I *could* do this:
-----
[%
   parts = str.split(pattern);
%]

[% IF parts %]
Found [% parts.size %] patterns in [% str %]
[% END %]
----

To create a whole array seems a little wasteful. 
What's the TT idiom to do this sort of thing?

Thanks. 


-- 
----------------
Joe Johnston -- http://taskboy.com
Software Consultant: Web - Database - Perl

_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://www.template-toolkit.org/mailman/listinfo/templates

Reply via email to