Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

cygwin

perl

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.

like image 393
brian d foy Avatar asked Jun 17 '12 19:06

brian d foy


2 Answers

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.

like image 189
ysth Avatar answered Sep 22 '22 20:09

ysth


Yes. For example:

    # show we're in cygwin
% uname -a
CYGWIN_NT-6.1-WOW64 xzodin 1.7.15(0.260/5/3) 2012-05-09 10:25 i686 Cygwin
    # show that directory is empty
% ls
    # create a file
% touch foo
    # invoke 'perl -pi' (but do nothing)
% perl -pi -e "" foo
    # show that a backup file with extension '.bak' is created.
% ls
foo  foo.bak
like image 30
Turvalar Avatar answered Sep 18 '22 20:09

Turvalar