in reply to Re^2: Executing "perl -pi -e" in perl script
in thread Executing "perl -pi -e" in perl script
Not much reinventing... You could nicely wrap it up into some sub like inplace_edit() that you then call every time you need "perl -pi -e...":
#!/usr/bin/perl use strict; use warnings; sub inplace_edit { my ($callback, @files) = @_; return unless ref($callback) eq "CODE"; local $^I = ""; local *ARGV; @ARGV = @files; while (<>) { $callback->(); print; } } inplace_edit( sub { s/(foo|bar)/*\U$1*/; }, "test.dat" ); __END__ $ cat test.cat foo bar baz qux $ ./833501.pl $ cat test.dat *FOO* *BAR* baz qux
|
|---|