Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Do I understand this?

by eskiphill (Novice)
on Jan 16, 2013 at 00:03 UTC ( #1013472=perlquestion: print w/replies, xml ) Need Help??
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 (Bishop) 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 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 ...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1013472]
Approved by blue_cowdawg
Front-paged by Lotus1
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2018-10-23 18:45 GMT
Find Nodes?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...

    Results (125 votes). Check out past polls.