Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Don't ask to ask, just ask
 
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 (Abbot) 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 (Monsignor) 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 drinking their drinks and smoking their pipes about the Monastery: (11)
As of 2014-04-25 08:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (585 votes), past polls