Is this unprecedented for a rename command or function?

Unprecedented, no. This is the way Unix has always behaved. You have to explicitly ask it to warn you if things are about to be overwritten, via the -i command line switch. On the other hand, I know you happen to be (mainly) a Windows developer, and on that platform you can't rename an old file into an existing file.

And it does say here "Changes the name of a file; an existing file NEWNAME will be clobbered. "... but who reads the documentation?

Does anyone else think that this is a DWIM too far?

No, in that I am accustomed to the behaviour and in fact rely on it. I appreciate being able to rename a new file into the name of a production file and I don't care whether the file exists or not.

Nonetheless, you do have a point. According to the principle of Least Surprise, perl should probably honour the underlying rename behaviour of the OS. But that opens up another can of worms. I have lots of cross-platforms scripts written once, run on both Windows and Unix. What happens then? I like having the consistent behaviour on both systems.

Maybe what is needed is a flag in Config that lets one choose which action to take when the target exists.

PS: now, about those backups...

- another intruder with the mooring of the heat of the Perl


In reply to Re: A DWIM too far? by grinder
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.