in reply to Read value from file, replace, then write to new file
There are multiple bugs in there. Off the top of my head, the worst ones are:
for (@copy_this) { s{ \*\*\* password \*\*\* }{$password}xms; }
open my $myfile_fh, '<', $readfile or die "Can't open $readfile +for input: $!"
Further, it makes no sense to do those "close" operations after the end of the sub. If you're going to do them explicitly at all, put them inside the sub.
There are a number of other stylistic objections that could be made: I would name the subs "generate_password" and "please_god_work" myself, and I'd probably slurp the whole file into one string like so: undef $/; my $myfile = <$myfile_fh>;, so then the change could be made in one step $myfile =~ s{\*\*\* password \*\*\*}{$password}xms;
Perhaps worst of all, you appear to be in the process of inventing your own system of html templates, and you'd really be better off using an existing one, e.g. Mason or Template::Toolkit.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Read value from file, replace, then write to new file
by Porculus (Hermit) on Dec 23, 2007 at 21:34 UTC |