eskiphill has asked for the wisdom of the Perl Monks concerning the following question:

I have a line that looks like this:
$var ~= s/<!--(.|\n)*-->//g;
My interpretation of this would be to delete any value that looks like < !-- [anything including an eol]--> otherwise pass it on. This makes sense as this is an old roll your own template system. Am I missing anything?

Replies are listed 'Best First'.
Re: Do I understand this?
by LanX (Saint) on Jan 16, 2013 at 00:08 UTC
    Yes, you do!

    It deletes HTML-comments, even if they span multiple lines.

    Anyway it's better (and less buggy) written as $var =~ s/<!--.*?-->//gs

    EDIT: Please note the .*? for non-greedy now, otherwise you are deleting everything in between the first and the last HTML-comment.

    see also Regex: Char-class equivalent for [^] for a recent discussion of '.' and '/s'

    Cheers Rolf

    UPDATE: corrected C&P typo ~=

Re: Do I understand this?
by grondilu (Friar) on Jan 16, 2013 at 06:35 UTC

    This will not answer your question but:

    I'm pretty sure you meant =~ and not ~=

    Sometimes I forget if it's =~ or ~=, so I use the following mnemonic: it is NOT supposed to be a contraction for $var = $var ~ $some_regex, so it is NOT ~=.

Re: Do I understand this?
by locked_user sundialsvc4 (Abbot) on Jan 16, 2013 at 16:37 UTC

    Yup, looks like roll-your-own-template cleverness.   If you can get rid of it, do so.   And if you can’t, document the hell out of it ...