Tim Booher wrote:
>
> Hello, I am currently frustrated trying to do a simple find and replace
> on a file, but the three open options: Read, Write and Append don't seem
> to give me what I want. For example, Read, works on the finding, but
> nothing will replace. Write erases all the files and leaves me with
> blank files and append adds to the end.
>
> I tried something like:
>
> open(MYFILE,'+<',$myfile);
>
> and that didn't work. If you are interested here is my code:
> .. . .
> open(HTMFILE,'+<', $filename) or die "Can't Open: $!"; # now
> go through all .htm files and make changes
> while (<HTMFILE>) {
> $_ =~ s/leftmargin="0".*bgcolor="#3c3939"//g;
> $_ =~ s/bgcolor="\#5A5D4E"/class="topOfPic"/ig;
> }
> close(HTMFILE);
> . . .
>
> any thoughts . . ?
Probably the simplest way is to use Tie::File.
use Tie::File;
tie my @data, 'Tie::File', $myfile or die "Cannot tie $myfile: $!";
for ( @data ) {
s/leftmargin="0".*bgcolor="#3c3939"//g;
s/bgcolor="#5A5D4E"/class="topOfPic"/ig;
}
untie @data;
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]