Another alternative is to use Tie::File. This lets you treat a file as a regular array variable. This is very convenient because it is easy to understand what is going on, as long as you are familiar with perl arrays.
use Tie::File; my( $file_name, $arg1, $arg2 ) = @ARGV; # open the file with tie tie my @file_lines, 'Tie::File', $file_name or die; # delete the first line shift @file_lines; # filter out lines containing 'sandwich' @file_lines = grep !/^$arg1,$arg2,/, @file_lines; # close the file with untie. # IMPORTANT: always untie when you are done! untie @file_lines or die "$!";
Update: Note that perl does not actually load the file into the array. It only appears to do so.
In reply to Re: How can I find and delete a line from a file?
by dimar
in thread How can I find and delete a line from a file?
by Cobra2411
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |