in reply to Add Contents At last in a File

Hi Swift,
You should take a look at perldoc -f open.

If you don't want to open twice, once for writing and again for reading, use "+<" as the mode for the initial open like so:

my $file = "D:/swift/file.tmp"; open (FILE, "+< $file") || die "Couldn't open $file: $!"; print FILE "Add some text"; close (FILE);

By the way, you don't need to double up backslashes; you can use single forward slashes as path delimiters on Windows. Just one less thing to worry about. And checking to see if open calls were successful is a good idea.

Hope this helps.

--
jpg

Replies are listed 'Best First'.
Re^2: Add Contents At last in a File
by AReed (Pilgrim) on Aug 09, 2005 at 13:34 UTC
    Danger, Will Robinson! This code begins writing at the beginning of the file, overwriting whatever was there. I don't think that's what the OP intended.

    To append to the file, just change "+<" to ">>" as davidrw suggested.