Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: Regex for removing Template::Toolkit comments?

by Corion (Patriarch)
on Aug 24, 2018 at 17:50 UTC ( [id://1221051]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Regex for removing Template::Toolkit comments?
in thread Regex for removing Template::Toolkit comments?

I don't understand what you mean by "Additional problem is the nested comments unless they are forbidden."? Can you show example input data where my regular expression fails?

If you have a regular expression for nested C comment literals, I'm quite sure that it can be trivially converted to a regular expression matching nested TT comments by changing /* to [%# and */ to %]. But I really doubt that TT allows for nested comments anyway.

Replies are listed 'Best First'.
Re^4: Regex for removing Template::Toolkit comments?
by bliako (Monsignor) on Aug 24, 2018 at 17:57 UTC

    It fails on the following which is bad practice on my behalf when I need to comment out entire html sections for debugging. That section may include TT directives or TT comments, e.g.:

    [% # abc [%# xyz %] %]

      I can't get that TT snippet to compile:

      use strict; use warnings; use Template; my $tt = <<'TT'; [% # this is a comment to the end of line foo = 'bar' %] <p>You might have an array in your TT</p> [% #foo = bar[5]; %] <p>bw, bliako</p> [%# placing the '#' immediately inside the directive tag comments out the entire directive %] A nested tag: [% # a comment abc = 1; [%# xyz %] %] TT use Template; my $parser = Template->new(); my $output = $parser->process(\$tt, { bar => [1,2,3,4,5]}) or die $parser->error; print $output; __END__ file error - parse error - input text line 16-18: unexpected token (%# +) [% # a comment abc = 1; [%# xyz %]

      I still doubt that Template Toolkit supports nested comments, but again, if you have a regular expression for nested comments in C, I already showed you what you need to change in it to make it work for TT comments.

        yes thank you.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1221051]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-25 05:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found