I'd appreciate help for the following:
Goal: Search a data file (lines delineated by carriage returns) for a given string. If found, delete line from file.
What I'm doing now is to load the file into an array and then going through the array one line at a time. If not equal the search term, the line is written to a backup file. If equal, the line is omitted and the line is saved to a variable for later use. Then the file is saved as the original data file.
So if the data file is:
apples
oranges
bananas
watermelons
and the search term is bananas then the resultant file would be:
apples
oranges
watermelons
and $deleted = bananas.
There must be a better way using an array function (like push) and reg exp.
Any suggestions?
Thanks... Dan
Goal: Search a data file (lines delineated by carriage returns) for a given string. If found, delete line from file.
What I'm doing now is to load the file into an array and then going through the array one line at a time. If not equal the search term, the line is written to a backup file. If equal, the line is omitted and the line is saved to a variable for later use. Then the file is saved as the original data file.
So if the data file is:
apples
oranges
bananas
watermelons
and the search term is bananas then the resultant file would be:
apples
oranges
watermelons
and $deleted = bananas.
There must be a better way using an array function (like push) and reg exp.
Any suggestions?
Thanks... Dan

