windowsperlinplace-editing

How can I do inplace editing (-i) with perl on windows?


In the unix/linux version, I'd simply change the first line:

#!perl -i.bak

Using Activestate perl on windows, where I've created the association with .pl, I can run a perl script directly from the command line.

myScript.pl

How can I do inplace editing of files if I still want to use the default association?


Solution

  • Sounds like a trick question, and I wonder if I am understanding you right.

    perl -pi.bak myScript.pl myfiletochange
    

    Just call perl, supply the switches and the script name, and off you go.

    Now, it may be that you do not want to supply these extra arguments. If so, you can simply set the variable $^I, which will activate the inplace edit. E.g.:

    $^I = ".bak"; # will set backup extension