in reply to Re: Delete last line of file with regex
in thread Delete last line of file with regex
my @lines = <DATA>; if ($lines[-1] =~ /^##/) { pop @lines; } my $slurp = join '', @lines;
Note that this will keep the entire file twice in memory (except for the very last line if it starts with ##). That's ok if you have only small files or large amounts of memory. But for large files and limited memory, this may get you into an out-of-memory situation.
See also perlfaq3 and perlfaq5.
Alexander
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Delete last line of file with regex
by Anonymous Monk on Jul 23, 2020 at 13:50 UTC | |
by Anonymous Monk on Aug 06, 2020 at 16:40 UTC |