$orginalFile = "c:\\file.txt";
$newFile = "c:\\newfile.txt";

$textToAdd = "New text\nSecond line ofnew text\n";

open IN, $originalFile or die "Can't open $originalFile: $!";
open OUT, ">$newFile" or die "Can't create $newFile: $!";

print OUT $textToAdd;

while(<IN>) {print OUT};

close IN;
close OUT;

That should do it. You can then delete the original file and rename the new
one like this.

unlink($originalFile) or die "Can't delete $originalFile: $!";
rename ($newFile, $originalFile) or die "Can't rename $newFile to
$originalFile: $!";

HTH

John
-----Original Message-----
From: COLLINEAU Franck FTRD/DMI/TAM
[mailto:[EMAIL PROTECTED]]
Sent: 02 August 2001 09:35
To: Perl (E-mail)
Subject: inserting lines


Hi!

How can i do to insert several lines in the beginning of a existant file ?

Thanks

Franck

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------Confidentiality--------------------------.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to