Search code examples
perlcygwin

Does perl's -i with no argument create a backup file on Cygwin?


I have a bug report from a reliable person that on Cygwin and Perl 5.14.2, using perl's -i switch with no value creates a .bak backup file. It shouldn't according to the documentation in perlrun:

If no extension is supplied, no backup is made and the current
file is overwritten.

I don't have access to Cygwin at the moment. Does anyone else see this behavior? Can you explain it? Is is something about creating the backup file, which should only be a temporary file, and failing to remove it?

Here's the steps I suggest to recreate it. Remember, this is for Cygwin:

  1. Create and change into empty directory
  2. Create a text file in that directory. The contents are not important
  3. Run perl -p -i -e 's/perl/Perl/g' filename
  4. Check for a .bak file when you are done

Save the answers for an explanation of what might be happening if you find that backup file. Upvoting a prior comment for "Yes I see that" or "No, can't reproduce it" can be an informal poll.


Solution

  • perldoc perlcygwin sayeth (edited for clarity):

    Because of Windows-ish restrictions, inplace editing of files with perl -i must create a backup of each file being edited. Therefore Perl adds the suffix .bak automatically — as though invoked with perl -i.bak— if you use perl -i with no explicit backup extension.

    Arguably this information should be in perlport also.