in reply to Avoid re-invocation for -pie processing

Hi, use Path::Tiny and edit_lines().

use strict; use warnings; use feature 'say'; use Path::Tiny; my $file = path('file.txt'); $file->spew("foo bar\nfoo bar"); $file->edit_lines(sub{s/bar/baz/}); say $file->slurp;
Output:
foo baz foo baz

Hope this helps!


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Avoid re-invocation for -pie processing
by seismofish (Novice) on Jan 08, 2024 at 11:02 UTC

    Thanks, 1nickt. That will do exactly what I want.

    <°}}}>«<