in reply to A Better Way

No, it doesn't have to be this cumbersome. There's no reason to write an array to a file, and then read the file and fill the array from the file.

I also don't see why you need to replace each newline with replace, and then later on do the reverse substitution.

It seems to me your whole script could be replaced by

$ perl -i -pe 's/the line to be replaced/this is the new line/' var.tx +t
Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^2: A Better Way
by toniax (Scribe) on Nov 04, 2010 at 16:54 UTC
    Thanks for your reply . I am new to programing . I did not know you could use a one liner in a cgi program. Would that not have to be called with system()? I am not familiar with one liners. Does that code replace all instances or just the first one is reads ? The reason I created my program in the above way Is so it only replaces the First Line in the Loop not Every Line it Loop Thanks again for all your help
      I did not know you could use a one liner in a cgi program

      And I did not know that you wrote a CGI program. It didn't say so anywhere in your original post, and since your program doesn't write a Content-Type header, it can't be valid CGI either.

      That said, you can still apply the -i option on the shebang line, see perlrun.

      Perl 6 - links to (nearly) everything that is Perl 6.
        Sorry .My bad .
        I will try to be more clear with my future post.