in reply to Removing duplicate line

Yes, don't print $body if you print $newline.

I'd rewrite your logic slightly, so you modify the line in place, using $_ instead of several unnecessary temporary variables. I could write the code for you, but you have to understand the logic first.

Update: Here's a crack at better code:

open (FILE, $filename) or die "Can't open $filename: $!"; while(<FILE>){ s/(a href=.+?\.)html/$1asp/g; s/(.*?)\<body\>(.*?)\<\/body\>/$2/i; print OUTFILE $_; } close(FILE);
There's no need to chomp or to carry extra things around. I'm not thrilled with the second regex, but I figure it's there for a reason. :)

Replies are listed 'Best First'.
Re: Re: Removing duplicate line
by Chady (Priest) on Apr 30, 2001 at 23:48 UTC

    Your second RegEx assumes the <body> and </body> tags are on the same line... and this is not always true.. check this for a better(?) solution..


    He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

    Chady | http://chady.net/
Re: Re: Removing dublicate line
by Anonymous Monk on Apr 30, 2001 at 23:18 UTC
    I just started learning perl last week, so its basically all new to me. I think I understand what you are saying about modifying the line in place, and I definetly know that Im not supposed to print twice, but Im just not sure how else to do it. Any help would be really appreciated.