develooper Front page | perl.perl5.porters | Postings from August 2010

What do we do about perl -pi on Windows?

Thread Next
From:
Ævar Arnfjörð Bjarmason
Date:
August 9, 2010 15:44
Subject:
What do we do about perl -pi on Windows?
Message ID:
AANLkTik54C51gd7Rji0MjvFJJyq_aqskoo8dQxL=2Ys5@mail.gmail.com
It came up on the Git list[1] that perl -pi -e 's///' isn't portable
to Windows for the same reason that sed -i isn't. Windows doesn't
support clobbering.

That leaves the question of what we should do. In 2002 Gerrit P. Haase
thought that should be, on Cygwin[2].

    +#if defined(__CYGWIN__) /* do backup extension automagically */
    +       if (*(s+1) == '\0') {
    +       PL_inplace = savepv(".bak");
    +       return s+1;
    +       }
    +#endif /* __CYGWIN__ */

That code is still sitting in perl.c today, silently turning "perl -pi
-e 's///'" on Cygwin into "perl -pi.bak -e 's///'".

Do we really want to do that? That means that this shellscript will
silently break on Cygwin:

    echo foo > f &&
    perl -pi -e 's/foo/bar/g' f &&
	grep -q bar f

Since perl will have silently created a f.bak with "bar" behind your
back.

Shouldn't we either die loudly saying that Windows doesn't support
clobbering with "perl -pi", or at least do the same thing on Cygwin,
Win32, MINGW etc? It seems nobody raised Unix shellscript
compatibility when this was applied in 2002[3].

What do the sed implementations that have been ported to Windows do?
Other than assume that they're still running on a Unix system, that
is.

1. http://kerneltrap.org/mailarchive/git/2010/8/8/36314/thread#mid-36314
2. http://perl5.git.perl.org/perl.git/commitdiff/c030f24b?hp=4c7fc0a422d59e20b533b9ae25dd19c2ebfb68b6
3. http://www.nntp.perl.org/group/perl.perl5.porters/2002/05/msg60275.html

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About