• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

substitution

I have an HTML file with comments like:

<!-- cgi:SOMETHING -->

I want to parse that file under two conditions. The first condition will replace those comments with data like($buffer contains the entire HTML file):

$buffer =~ s/<!-- cgi:SOMETHING -->/$my_data/g;

The other instance of parsing this file get rid of those comments alltogether. So I want to parse $buffer and anywhere it sees a comment, it replaces it with nothing. However, the SOMETHING in the comment will be different for each comment, so how would I write the substitution command to replace all comments with nothing?

-Mike K.
0
lunaboy
Asked:
lunaboy
1 Solution
 
djsansuiCommented:
I think what you're aiming for is:
$buffer =~ s/<!--(.|\n)*-->//g;
0
 
lunaboyAuthor Commented:
no, that deletes all the lines that contain comments... I just need to delete the comments themselves...
0
 
lunaboyAuthor Commented:
no, that deletes all the lines that contain comments... I just need to delete the comments themselves...
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
PC_User321Commented:
$buffer =~ s/<!--.*?-->//g;
0
 
pitonyakCommented:
Will the comments have any particular structure such as potentially including embedded HTML then you have a little problem. My concern is that you will end your replacement before you need to. Also, will there be any escape characters?

0
 
lunaboyAuthor Commented:
pitonyak - The comments will only be like:

<!-- cgi: SOMETHING -->

where SOMETHING is any single word. It's used for a template. The script parses the HMTL file, replaces the comments with the appropriate data, and prints it. However, I have another script that I wanted to print the same HTML without the dynamic data. So I wanted that script to replace all those comments with nothing.

PC User321 answered correctly, he will get the points this time.

-Mike K.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now