> -----Original Message----- > From: Jeff Westman [mailto:[EMAIL PROTECTED]] > Sent: Sunday, December 15, 2002 2:20 PM > To: [EMAIL PROTECTED] > Subject: Read-Write Mode Not Working > > > Hi, > > I'm using ActivePerl 5.6.1. I am trying to update an existing file. > According to perlfaq5.pod, I should be able to use: > > open(FH, "+< /path/name"); # open for update > > However, I this doesn't seem to update the file for me: > > #----------(begin)---------# > #! perl -w > $| = 1; > $file = "myFile"; > open(FILE, "+< $file") or die "Could not open file, $file: $!\n"; > while (<FILE>) { > # do whatever (read) > print; > } > > # write a line to the file > print FILE "\ntest line\n"; > close(FILE); > #----------(end)-----------# > > This runs and displays the file, but the added line is > missing. Any ideas > why?! Thanks in advance.
Some systems require you to call seek() when switching from reading to writing. By adding: use Fcntl qw(SEEK_END); to the top of the script, and: seek FILE, 0, SEEK_END; to just before the print FILE line, I was able to get your example working on Win32 using ActiveState. HTH -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]