Home: Perl Programming Help: Regular Expressions:
A quicker Way



perlkid
stranger

Jun 19, 2000, 11:29 PM


Views: 10597
A quicker Way

 
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


Views: 10597
Re: A quicker Way

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


Views: 10597
Re: A quicker Way

 
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


Views: 10597
Re: A quicker Way

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


Views: 10597
Re: A quicker Way

 
Thanks For The Nifty Code Japhy. Smile

I'll be using that too!

perlkid