in reply to Best way to write in Perl

hello fellow monk,

yes there is a facility in perl to modify a file (i.e. to do inline replacement)

 perl -pi -e 's/MONK/SAINT/ig' abc.txt

The above file will replace all the instances of MONK to SAINT in the file abc.txt

hope it helps,

Blessings,
a perl Monk

Replies are listed 'Best First'.
Re^2: Best way to write in Perl
by j1n3l0 (Friar) on Sep 04, 2007 at 09:17 UTC
    I think you forgot to create a backup of the file. I tried:

    perl -pi -e 's/MONK/SAINT/ig abc.txt

    and get:

    Can't do inplace edit without backup.

    If you change that to:

    perl -pib -e 's/MONK/SAINT/ig' abc.txt

    Then it works ;)


    Smoothie, smoothie, hundre prosent naturlig!
      Actually, just specifying -i will work on most platforms. Cf perldiag :
      Can’t do inplace edit without backup (F) You’re on a system such as MS-DOS that gets confused if + you try reading from a deleted (but still opened) file. You have t +o say "-i.bak", or some such.