Unix has been around for longer than Windows has with fewer changes to basic things such as this. While this is a poor measure of correctness, I think it says something.

It says something. Quite what it says is open to question.

Of course the behaviour makes sense to Unix heads familiar with how the C rename() operates. Which is a plus. Less to learn.

Apart from this, and being simple to implement, is it a good decision?

demerphq says that it's "much more common to want to rename things and overwrite what was there before". This is reasonable, but (after a quick grep of the Perl I have laying around) it doesn't match my experience.

The current behaviour certainly makes coding some operations harder. If rename failed if the new filename existed we could do:

rename( $old, $new ) || die $!;

and be certain that $new won't be damaged if it already exists. However, with the current behaviour we either have to abandon rename completely and spend a lot of time and effort doing sneaky stuff, or do something like :

! -e $new && rename( $old, $new) || die $!

which is both longer to type, and has a race condition ($new could be created between the die and the rename).

Personally I would prefer rename to fail by default with an option to overwrite. It would make my code more robust.


In reply to Re^4: A DWIM too far? by adrianh
in thread A DWIM too far? by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.