in reply to Avoid re-invocation for -pie processing

These days I would prefer something like:

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11156715 use warnings; use Path::Tiny; sub delete_comments_from_file { path($_)->edit( sub { s/#.*//g } ) for @_; } my $file = '/tmp/foobar.tmp'; path($file)->spew( <<END ); one # a comment two no comment three # more comments; END print path($file)->slurp; print '-' x 50, "\n"; delete_comments_from_file( $file ); # NOTE print path($file)->slurp;

Outputs:

one # a comment two no comment three # more comments; -------------------------------------------------- one two no comment three

There is also a edit_lines() version for 'one-line-at-a-time'.