A couple of things. 1. Your list of stuff in the test directory will have some directory entries in it, at least . and .., which open will not open.
2. If you do open a file for output and read line at a time it will wipe out the original file so you will need to read in the files then open for output then write.
Look at the -i flag to perl which may give some direction. If you want to use readdir you will need to stat the files to see if they are regular files and only open those, read in the data, reopen the file for output and write. If you have a failure (as in power) you will lose your original file.
I would recommend a two tier approach. Open a temp file to write and open the file to read, copy changes into the temp file and then use the rename() function to change the name back to the current filename which will be a lot safer to your original data.
In reply to Re: BAsic File I/O
by dga
in thread BAsic File I/O
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |