in reply to Re: Keep file formatted
in thread Keep file formatted
And, of course, you could move the check on the @variables outside the processing loop. Then you'll get an error, and no output, rather than half the output and an error. Also, the filename really, really ought to be validated in someway, in case somebody submits (for example) "> /etc/passwd", which would promptly attempt to erase your password file (I'm only going to force the file to be opened for reading, which still isn't adequate, but it's an improvement).
foreach $variable (@variables) { die "Incomplete $variable\n" if $FORM{$variable} eq ""; } open FILE, "< $FORM{'TextFile'}" or die "Cannot open TextFile $FORM{'TextFile'}"; foreach $line (<FILE>) { foreach $variable (@variables) { $line =~ s/<!--$variable-->/<STRONG>$FORM{$variable}<\/STRONG>/g; } $line =~ s/A\/an <STRONG>(a|e|i|o|u)/An <STRONG>$1/g; $line =~ s/a\/an <STRONG>(a|e|i|o|u)/an <STRONG>$1/g; $line =~ s/A\/an/A/g; $line =~ s/a\/an/a/g; print "$line\n"; } close FILE;
--
Tommy
Too stupid to live.
Too stubborn to die.
|
|---|