Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Do I understand this?

by eskiphill (Initiate)
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?

Comment on Do I understand this?
Download Code
Re: Do I understand this?
by LanX (Canon) 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 (Pilgrim) 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?
Username:
Password:

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
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2015-07-06 21:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (83 votes), past polls