CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



Flomble
New User

Mar 21, 2002, 8:51 AM

Post #1 of 2 (3823 views)
Periods vanish after s///; command? Can't Post

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:

<BEGIN>

BLAH BLAH

BLAH

<END>



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


Code
  

foreach $Line (@Lines) {

chomp($Line);

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?


Paul
Enthusiast

Mar 21, 2002, 1:16 PM

Post #2 of 2 (3815 views)
Re: [Flomble] Periods vanish after s///; command? [In reply to] Can't Post

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;

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives