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

What do we do about perl -pi on Windows?

Thread Next
Ævar Arnfjörð Bjarmason
August 9, 2010 15:44
What do we do about perl -pi on Windows?
Message ID:
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

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


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About