Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Can't rename

by wolverina (Beadle)
on Mar 18, 2004 at 06:43 UTC ( #337624=perlquestion: print w/replies, xml ) Need Help??

wolverina has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Can't rename
by b10m (Vicar) on Mar 18, 2004 at 10:10 UTC

    In case you have no clue why something doesn't work, just add debug print statements everywhere, so you can see what is the problem.

    My guesses are: file1.htm is not in $ENV{DOCUMENT_ROOT}, or your webdaemon user (apache, www, nobody...) doesn't have sufficient rights to write to $ENV{DOCUMENT_ROOT}

    Besides that, you can also skip the chdir() command and try it with the use of full path names in the rename() command. Something like:

    $a = "$ENV{DOCUMENT_ROOT}/file1.htm"; $b = "$ENV{DOCUMENT_ROOT}/file2.htm"; rename($a, $b) || die "Uh oh, can't rename: $!";
    --
    b10m

    All code is usually tested, but rarely trusted.
Re: Can't rename
by davido (Cardinal) on Mar 18, 2004 at 07:11 UTC
    Check your server's error logs, or use CGI::Carp with fatalsToBrowser so that you can actually see whether the script is dieing at the chdir stage, the rename stage, or somewhere else. Once you do that you'll probably find the answer to this question without too much additional guidance.

    I would suspect improper permissions, or maybe an invalid path.


    Dave

Re: Can't rename
by kvale (Monsignor) on Mar 18, 2004 at 06:49 UTC
    It's hard to say without knowing more information. What error are you getting? Does the program die, or does it fail silently?

    If you are executing this as a CGI program, you may want to check permissions on the files and directories.

    -Mark

Re: Can't rename
by ambrus (Abbot) on Mar 18, 2004 at 07:21 UTC

    In windows, I think it's an error to suffix directory names with a backslash, at least in some versions. Do you need the slash after $ENV{DOCUMENT_ROOT}?

    Also, why do you die with "Can't open" when it's chdir that fails?

Re: Can't rename
by nimdokk (Vicar) on Mar 18, 2004 at 10:51 UTC
    In addition to the suggestion about setting $a and $b to the full path to the file, you might also want to make sure that $ENV{DOCUMENT_ROOT} is really being set to what you are expecting it to be. Perhaps adding use strict or use warnings?

    update: I just got into work and skimmed my Perl book. From the docs, "rename will not (usually) work across filesystem boundaries, although on a Unix system, the mv command can sometimes be used to compensate for this." It goes on to add: "See the standard File::Copy module for cross-filesystem renames."


    "Ex Libris un Peut de Tout"
Why don't you ever post the error message you get?
by Anonymous Monk on Mar 18, 2004 at 07:11 UTC
    Well?
    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://337624]
Approved by kvale
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2021-03-06 09:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (116 votes). Check out past polls.

    Notices?