nysus has asked for the wisdom of the Perl Monks concerning the following question:
I want to delete the last line of a file but only if it begins with ##
#!/usr/bin/env perl my $slurp; while (<DATA>) { $slurp .= $_; } $slurp =~ s/^###* [^\n]+//m; print $slurp; __DATA__ kjkjksjdf ## Don't del me blah ## deleteme
I don't know how to indicate that nothing should come after the line or how to indicate EOF in a regex.
$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Delete last line of file with regex
by choroba (Cardinal) on Jul 22, 2020 at 18:33 UTC | |
Re: Delete last line of file with regex
by tybalt89 (Monsignor) on Jul 22, 2020 at 17:41 UTC | |
Re: Delete last line of file with regex
by jwkrahn (Abbot) on Jul 22, 2020 at 22:13 UTC | |
Re: Delete last line of file with regex
by ForgotPasswordAgain (Vicar) on Jul 23, 2020 at 01:38 UTC | |
Re: Delete last line of file with regex
by dsheroh (Monsignor) on Jul 23, 2020 at 08:02 UTC | |
by afoken (Chancellor) on Jul 23, 2020 at 08:18 UTC | |
by Anonymous Monk on Jul 23, 2020 at 13:50 UTC | |
by Anonymous Monk on Aug 06, 2020 at 16:40 UTC | |
Re: Delete last line of file with regex
by perlfan (Parson) on Jul 23, 2020 at 02:25 UTC |