Hi, I'm relatively new to PERL, so forgive me if this question is a little basic. I'm working on a project where the user supplies a file. I wish to copy the contents of this file to a different file, while searching for specific variables and changing the value of these variables. Also, if a variable I'm searching for doesn't appear in the original file, I would like to add it to the copied file. So basically if File1 contains:

$Var1 = 1; $Var2 = 2;

I would like to copy this to File2, changing the values of Var1 and Var2, while adding the line $Var3 = 6, so that File2 contains:

Here I'm simply reading the contents of Filename1, finding the string $Var1, and replacing it with the string $Variable1. This is not exactly what I want to do though. I would like to replace the value of $Var1 after the equals sign, but I don't know how to do that. I would also like to scan Filename1 for each variable, and if it is not in Filename1, add it to Filename2 directly below an anchor point, say Var0.

Re: [madonion55] Copy and change contents of one file to another
[In reply to]

Can't Post

In modern perl, you don't use bareword filehandles. In modern perl, you use the 3-arg form of open. In modern perl, you output the system error message if open() fails. In modern perl, you start every program with the equivalent of the first three lines below.

Re: [7stud] Copy and change contents of one file to another
[In reply to]

Can't Post

I appreciate your quick replies. I tried copying and pasting your code to test it out, but it turns out I only have Perl V5.8.4 available. I tried your script with this version anyway, but I got an error saying it can't locate object method "say" via package "FileHandle." Is there a way around this?