in reply to Write to file
As mentioned (indirectly) by Fletch, Tie::File probably fits your needs best. It allows you to treat a file as an array. Anything you do to the array will be reflected by the file. I just wanted to provide some usage tips:
To remove a line from the file, use splice. For example, splice(@tied_to_file, 10, 1); removes one line, starting with the 11th one (0-based indexes).
splice is also used to insert lines. For example, splice(@tied_to_file, 10, 0, @lines_to_insert); inserts the provided lines before the 11th line (0-based indexes).
You can use grep to apply filters to every line of your file. For example, @tied_to_file = grep { !/DELETE ME/ } @tied_to_file;
You can use map to apply transformations to every line of your file. For example, @tied_to_file = map { uc($_) } @tied_to_file;
|
|---|