http://qs1969.pair.com?node_id=621437


in reply to unix mv command

I have no idea what's in those variables, so I can't really tell you. Perhaps $different_path has spaces in it?

Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart

Replies are listed 'Best First'.
Re^2: unix mv command
by xmanamit (Initiate) on Jun 15, 2007 at 12:09 UTC
    I have tested the paths, and they are fine as I used the perl mv command using File::copy module with the same variables. But can't understand why this doesn't work.
      If you let us see the paths, then we may be able to explain it.

      Clint

      I have tested the paths, and they are fine as I used the perl mv command using File::copy module with the same variables. But can't understand why this doesn't work.

      Non sequitur. Suppose that $from='foo' and $to='bar baz'. If you pass these arguments to F::C's mv(), then it will try to move the the file named foo to that called bar baz - with a space in it. If you do

      system("mv $from $to");

      as in your first post, a shell will be started which in turn will call the external mv program with the three cmd line arguments foo, bar and baz. (Well, upon a closer look to the docs it seems that it will call the shell only if there are shell metacharacters, but the final result won't change.) This may not be your case, but it serves as an instructive example. Alternatively use the LIST form of system, which will avoid the shell in any case and more likely do the Right Thing™ - and check its return value:

      0 == system 'mv', $from, $to or warn "Something wrong: $?\n";