Over a million developers have joined DZone.

Perl Inline File Edit Straight From Perl FAQ

·
// description of your code here


#!/usr/bin/perl

use strict;
use warnings;

my $filename = 'some_file.txt';
my $find = 'this';
my $replace = 'that';

{
   local @ARGV = ($filename);
   local $^I = '.bac';#<-- invokes inplace editing
   while( <> ){
      if( s/$find/$replace/ig ) {
         print;
      }
      else {
         print;
      }
   }
}
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}