Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: A DWIM too far?

by QM (Parson)
on Jun 18, 2004 at 01:24 UTC ( [id://367825]=note: print w/replies, xml ) Need Help??


in reply to Re^2: A DWIM too far?
in thread A DWIM too far?

As is, the behaviour makes it impossible to safely rename a file.
It makes it harder, at least:
sub myrename { my $rename = ( $^O eq 'MSWin32' ) ? 'move -y' : 'mv -i'; `$rename @_[0,1]`; return $!; } myrename('abc','def') or die $!;
I can't recall how to do this to the CORE, perhaps someone will remind me?

-QM
--
Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re^4: A DWIM too far?
by ihb (Deacon) on Jun 18, 2004 at 02:22 UTC
    It seems you answered the wrong question. The problem is that you can't be sure to not overwrite a file by renaming it. Your rename subroutine does quite the opposite. Or have I completely misunderstood your reply?
      I think you misunderstood (at least, I hope I've understood :)

      Rewriting rename to include the -i option (or -y option for Windoze) will not clobber an existing file (unless the underlying OS function has the same problem with the -i option, in which case we're all screwed.)

      I tried my example out, and it seemed to work as I intended. I'm sure someone has come up with a more robust and useful version. I was just trying to show that it was possible.

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of

        The /Y operator on windows forces it to overwrite without confirmation /-Y forces confirmation and there is no documented way to force failure when a file exists already.


        ___________
        Eric Hodges
Re^4: A DWIM too far?
by BrowserUk (Patriarch) on Jun 18, 2004 at 01:40 UTC
    *GLOBAL::CORE::rename = \&myrename;

    Update: The above is wrong! It should be

    *CORE::GLOBAL::rename = \&myrename;

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon
      Great! Is it possible to say
      sub *GLOBAL::CORE::rename {...}
      directly? Or is it a two step process?

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of

        Actually, I got the CORE and GLOBAL the wrong way around. It should be

        *GLOBAL::CORE::rename = \&myrename;

        Or to do it in one step something like

        sub CORE::GLOBAL::rename{ system "ren $_[ 0 ], $_[ 1 ]"; return $? >> 8; }

        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
        "Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://367825]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-24 22:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found