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:
A quicker Way

 



perlkid
stranger

Jun 19, 2000, 11:29 PM

Post #1 of 5 (4820 views)
A quicker Way Can't Post

 
Does any body know of a quicker way to get rid of multiple lines of html without having to s///; them out one by one. I'd like to be able to do this

s/the whole line .* the whole line about ten lines below the first//;

This would be really usefull for getting rid of forms or tables with out effecting other tables and forms.

Thanks Smile

perlkid


Kanji
User / Moderator

Jun 20, 2000, 9:00 AM

Post #2 of 5 (4820 views)
Re: A quicker Way [In reply to] Can't Post

Assuming everything is in one variable ...

$lines =~ s/^(.*\n){11}//;

(11 is the number of lines to delete: first and the 10 below it.)


perlkid
stranger

Jun 20, 2000, 1:58 PM

Post #3 of 5 (4820 views)
Re: A quicker Way [In reply to] Can't Post

 
Thanks Kanji,

I was able to use that code to take out a number of lines in the middle of an html document without a problem. That code is great, I have been trying to take out bulk amounts of html and now I can take out 120 lines of useless html with no hassle. Thanks again Kanji, parsing will never be the same for me. Smile

perlkid


japhy
Enthusiast / Moderator

Jun 21, 2000, 11:12 AM

Post #4 of 5 (4820 views)
Re: A quicker Way [In reply to] Can't Post

If you are going through a file, I'd suggest:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


open FILE, "file";
while (<FILE> ) {
next if 5 .. 15; # skip lines 5 through 15
print;
}
close FILE;

# or

open FILE, "file";
while (<FILE> ) {
next if /<html>/ .. m!</html>!; # skip all lines between open and close <html> tags
print;
}
close FILE;
</pre><HR></BLOCKQUOTE>


------------------
MIDN 4/C PINYAN, NROTCURPI, US Naval Reserve


perlkid
stranger

Jun 22, 2000, 10:32 AM

Post #5 of 5 (4820 views)
Re: A quicker Way [In reply to] Can't Post

 
Thanks For The Nifty Code Japhy. Smile

I'll be using that too!

perlkid

 
 


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

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