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

Re: What do we do about perl -pi on Windows?

Thread Previous | Thread Next
Ævar Arnfjörð Bjarmason
August 9, 2010 16:15
Re: What do we do about perl -pi on Windows?
Message ID:
On Mon, Aug 9, 2010 at 23:05, Jan Dubois <> wrote:
> On Mon, 09 Aug 2010, Ævar Arnfjörð Bjarmason wrote:

>> 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

Bah, I mean:

    echo foo > f &&
    perl -pi -e 's/foo/bar/g' f &&
    grep -q bar f &&
	! test -f bar.bak ## *boom* on Cygwin

The substitution itself works.

>> On Mon, Aug 9, 2010 at 22:44, Ævar Arnfjörð Bjarmason <> wrote:
>> > Shouldn't we either die loudly saying that Windows doesn't support
>> > clobbering with "perl -pi"
>> It turns out (as pointed out by Jan Dubois) that we've been doing
>> exactly that since Perl 3:
>> Since about then we've been dying on DOSISH and AMIGA, it's just
>> Cygwin that's the exception.
>> Maybe that exception can be removed now? It was just added as a
>> workaround to get the KDE build system working on Cygwin. It seems odd
>> to have such a monkeypatch in perl core.
> The problem is that the monkeypatch is documented (in README.cygwin), so
> just removing it doesn't feel quite right either. Ideally someone would
> go in and update the patch to remove the backup file when it is being
> closed. Then this patch could be enabled for other DOSISH platforms too
> (maybe with a somewhat more obscure extension than .bak to avoid
> conflicts with existing filenames).

If we're set on adding perl -pi emulation on Windows it would probably
be best just to create a backup file with the equivalent of
File::Temp, and unlink it when we're done with it.

The only problem with that is that perl might run out of diskspace
when doing -pi on large files, or slowly accumulate garbage if it's
e.g. being killed before it gets around to the unlink().

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