in reply to Opening a file for reading or writing (was: Newbie)

The '>' in the open call truncates and open's the file for writing. You want to open it in in update mode ('+<'). This will open it for reading and writing.

Try this:

#!/usr/local/bin/perl -w use strict; use warnings; open(FILE, "+<height.txt") || die "file can't be opened"; my @file = <FILE>; # Read entire file into array map{ s/'/\t/g } @file; # substitution on each element seek(FILE,0,0); # go back to the beginning of the file truncate(FILE, tell(FILE)) # truncate from here to end of file print FILE @file; # write back to file close FILE;
I don't really think you need the truncate() here... but it's safer. If the size of the data you wind up writing to the file is smaller then the size of the original file, the truncate will get rid of that excess data. Which is not the case here. But it's good habit.

- FrankG