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:

  1. You're not assigning the return from "generatePassword" to a variable, so there's no way that "pleaseGodWork" can do anything with it.
  2. You need to make the change to the appropriate line in @copy_this, e.g.
    for (@copy_this) { s{ \*\*\* password \*\*\* }{$password}xms; }
  3. the "open (MYFILE" line is missing the '<' you need to indicate read access, and while you're at it you might as well be using open in the modern style:
    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
    the "open (MYFILE" line is missing the '<' you need to indicate read access
    This may be considered poor style, but it's not exactly a bug. '<' is optional.