in reply to substuting a whole file
Do you mean to be inconsistent here? Or should "UL" be "<UL>"?my $file = "index.html"; my @codes = ("<P>", "<BR>", "UL"); # and many more
Your open is clobbering index.html. Not what you want. Also, you never write out to the file to actually change it in memory.open(FILE, "> $file") or die "Oops: $!"; while(<FILE>);
Here's where you have your real problems. The if statement compares the file line to the number of items in @codes. Probably not what you want. Also, eq won't work unless you have only one word per line. Also probably not what you want.if ($_ eq @words) { $_ =~ s/@words/lc @word/g; }
Way to go.close(FILE);
Call it with the filename as argument.#!/usr/bin/perl -i use warnings; use strict; my @codes = ("<P>", "<BR>", "<UL>"); # and many more while(<>); for my $word (@words) { $_ =~ s/$word/lc $word/g; } close(FILE);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: substuting a whole file
by Roger (Parson) on Jan 14, 2004 at 03:55 UTC | |
by jweed (Chaplain) on Jan 14, 2004 at 03:57 UTC |