On Mon, May 10, 2004 at 11:51:08AM +1000, Timothy Duke wrote:

> Version #1 (works dreadfully....stuffs up the file)
> 
> #! perl  -w -i
> $filetobechanged = "iBook HD:Desktop Folder:tim.txt";
> open(FILE, "+< $filetobechanged") ;
> while (<FILE>) {
>     s/\n//g;
>     print FILE ;
>         }
> close(FILE);

You've opened the file for read-write, but you're mixing your reads and
your writes without using seek() to manage your location in the file.  You
read in the first line, then write it back out over the second line.
Instead you should just use in-place editing (-i), which writes out a copy
of the file and then replaces the original.

Ronald

Reply via email to