in reply to Re: Oneliner replace in-place adds extra spaces at the end of the file
in thread Oneliner replace in-place adds extra spaces at the end of the file

The solution here isn't to switch the order of -l and -0, but to remove -l entirely.


I use the suggested -0777 when I really want slurp mode

For the curious,

Replies are listed 'Best First'.
Re^3: Oneliner replace in-place adds extra spaces at the end of the file
by haukex (Archbishop) on Oct 27, 2025 at 09:22 UTC
    The solution here isn't to switch the order of -l and -o, but to remove -l entirely.

    Yes, that's a good point, in bliako's example the -l isn't needed, e.g. perl -i -0777pe 's/2/4/gs'.

    In general, one might still want to use -0777 and -l together to change $\. A few more TIMTOWTDI examples doing that:

    $ perl -MO=Deparse -0777l11ne ... BEGIN { $/ = undef; $\ = "\t"; } ... $ perl -MO=Deparse -l11n0777e ... BEGIN { $/ = undef; $\ = "\t"; } ... $ perl -MO=Deparse -ln0777e ... BEGIN { $/ = undef; $\ = "\n"; } ...
Re^3: Oneliner replace in-place adds extra spaces at the end of the file
by bliako (Abbot) on Oct 27, 2025 at 11:42 UTC

    thanks for this. minor neatpick: in the whole thread I see different renderings for the number Zero, compare 0, 0 and 0 and 0, I guess your -o is actually -0? I will use -0777 from now one because my files are not huge and slurping gives me more flexibility. Indeed -l and s///g*s* were from my wider use-case.

      Yeah, one use was accidentally the letter "o". Fixed.