Home: Perl Programming Help: Regular Expressions:
Periods vanish after s///; command?

New User

Mar 21, 2002, 8:51 AM

Views: 8854
Periods vanish after s///; command?

I have this script that opens a template, goes through each line, and if the line matches a certain tag, it deletes all the lines after it until another line matches a certain tag. For example:





It would see the begin tag, and delete the lines inbetween until it found the END tag. Here is the code I am using:


foreach $Line (@Lines) {


if ($Line =~ m/\<!--BEGINPAGETOP --\>/i) { $DontWrite = "YES"; }

if ($Line =~ m/\<!--BEGINPAGEBOTTOM --\>/i) { $DontWrite = "YES"; }

if ($Line =~ m/\<!--BEGINTABLEOUTPUT --\>/i) { $DontWrite = "YES"; }

if ($Line =~ m/\<!--BEGINMINIOUTPUT --\>/i) { $DontWrite = "YES"; }

if (($DontWrite ne "YES") && ($Line ne "")) { $WriteMe .= qq($Line\n); }

if ($Line =~ m/\<!--ENDMINIOUTPUT --\>/i) { $DontWrite = "NO"; }

if ($Line =~ m/\<!--ENDTABLEOUTPUT --\>/i) { $DontWrite = "NO"; }

if ($Line =~ m/\<!--ENDPAGETOP --\>/i) { $DontWrite = "NO"; }

if ($Line =~ m/\<!--ENDPAGEBOTTOM --\>/i) { $DontWrite = "NO"; }


For some damn reason, each time it does this routine, one period (.) in the template is stripped. So if I have:

welcome to mysite.org.

The first run it becomes:

welcome to mysiteorg.

When I run again:

welcome to mysiteorg

I can't figure out why it is doing this. Can someone help me?


Mar 21, 2002, 1:16 PM

Views: 8846
Re: [Flomble] Periods vanish after s///; command?

Why not use a unique tag that wont clash with html ie...

<%begin%> blah <%end%>

Then get your page into a string and do:

$string =~ s/<%begin%>.*?<%end%>//g;