Template-Alloy

 view release on metacpan or  search on metacpan

samples/benchmark/bench_template_tag_parser.pl  view on Meta::CPAN

        if ($j == -1) { # missing closing tag
            $last = length($_[0]);
            last;
        }
        my $tag = substr($_[0], $i + $len_s, $j - ($i + $len_s));
        $new .= "($tag)";
    }
    return $last ? $new . substr($_[0], $last) : $_[0];
}

### using a split method (several other split methods were also tried - but were slower)
sub parse_split {
    my $new = '';
    my $START = quotemeta '[%';
    my $END   = quotemeta '%]';

    my @all = split /($START .*? $END)/sx, $_[0];
    for my $piece (@all) {
        next if ! length $piece;
        if ($piece !~ /^$START (.*) $END$/sx) {
            $new .= $piece;



( run in 0.557 second using v1.01-cache-2.11-cpan-71847e10f99 )