in reply to $^I why this symbol does not work ?

You don't tell us how it does not work. But I'm going to guess. You're running this on Windows. On Windows, it's not possible to recreate a file while still reading from it. That's why you need to set $^I. You can still erase the file afterwards.

Also see the Sysadm::Install module, which has the pie subroutine, which does just what your replace subroutine does.

Replies are listed 'Best First'.
Re^2: $^I why this symbol does not work ?
by kingwrcy (Initiate) on Oct 01, 2008 at 06:45 UTC
    to:Corion\
    Yes.my OS is windows XP.
    you mean :In windows XP, when a fle is opened,we cannot save/modify it at the sametime ?
    now i want to replace some words then save it ,how i should do?
    perl -p -i -e "s/<String to Find>/<String to replace>/g" <File Name>
    I try this ,an error occurs :Can't do inplace edit without backup.
    i don't want any bakup files .
    this is a shortcut,If i want to write a program,how i finish this job ?

      No. Under Windows, you cannot use -i, you have to use -i.bak or something like that, because you cannot "rewrite" a file on the fly, at least not with the simple approach that the -p switch does.

      You will need to create the backup file and then erase it afterwards.

        Oh.i got it.
        i must create a BAK files .And then i can delete it,:-D.
        thanks all above.
      On windows system, you can use the following one liner.
      perl -pi.bak -e "s/<String to Find>/<String to replace>/;" <File Name>
      And ofcourse, it will create a backup of original file with .bak extension.
        i got it.
        thank you!:-D