[comp.lang.perl] perl -i bug

rhall@convex.com (Randy Hall) (12/16/90)

I ran into this problem using perl (patch level 40).

Using perl -i to edit a file in place fails when the directory is not
writable.  The file is zeroed, and no warning is given.

Create FILE which has write permission.  Put it in a directory which does
not have write permission.  Try:  perl -p -i.bak -e "s/foo/bar/" FILE

I think this is what happens:  perl will try to rename FILE to FILE.bak,
but cannot because write permission is denied.  Then perl tries to read
from FILE.bak putting the output in FILE.  This results in zeroing FILE.

I think perl should quit after not being able to make the backup and print
an error message.  If no backup is requested, perhaps perl could use /tmp
when the current directory isn't writable.

Thanks,
Randy Hall

rhall@convex.com	Convex Computer Corporation	Richardson, TX

tchrist@convex.COM (Tom Christiansen) (12/17/90)

Speaking of 'perl -i' bugs...  I just did this

    % mkdir testdir
    % perl -i -p -e 's/x/x/' testdir
    Can't do inplace edit.

Which is nice, although the file's name and why would be nice.

But this is really what I would consider wrong:

    % perl -i.bak -p -e 's/x/x/' testdir
    % ls -Fd testdir*
    testdir*      tdestir.bak/

Don't you think?

--tom
--
Tom Christiansen		tchrist@convex.com	convex!tchrist
"With a kernel dive, all things are possible, but it sure makes it hard
 to look at yourself in the mirror the next morning."  -me