Re: Perl Rename function unreliable?
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 22 Jul 2005 16:35:14 -0700
Rhugga wrote:
> Has anyone experienced problems using perl rename() function? We have
> seen odd results using 3 different versions of perl.
"odd results" is not a particularly helpful error description.
> I have some code
> that renames some oracle archive logs and out of a run of say 100 logs
> it will fail to rename a handfull.
"fail"s in what way? The rename() function returns a false value, or
the rename() function returns true but the files remain un-renamed?
> I examine that file stats and they
> are all identical in every possible way. (just different ctime/atime
> etc...) Perms are identical. The files are not open by another process
> (even though this doesnt matter per the documentation)
>
> I even added a sleep(5) between each rename() call.
>
> My OS types are a mix of Solaris 8 and 9.
Have you read the caveats about this function in
perldoc -f rename
?
> I'm using the rename command as follows:
>
> rename( $oldfile, $newfile) || die "Unable to rename $oldfile, manual
> intervention required.";
You ask the progrma to die, but don't bother asking Perl to tell you
*why* rename() failed? Why are you not including the $! variable?
> Is using this any less robust:
>
> `/usr/bin/mv $oldfile $newfile`;
The above is "wrong" in several ways.
* It's not portable
* You're not checking the return value, so you have no idea if it
succeeded or not.
* back-ticks are not what you should be using unless you're trying to
capture the output... and you're not capturing the output. Please see:
perldoc -f system
Have you seen the posting guidelines for this group? Please post a
short-but-complete script that demonstrates your error.
Paul Lalli
.
- Follow-Ups:
- Re: Perl Rename function unreliable?
- From: Rhugga
- Re: Perl Rename function unreliable?
- From: Dave Weaver
- Re: Perl Rename function unreliable?
- References:
- Perl Rename function unreliable?
- From: Rhugga
- Perl Rename function unreliable?
- Prev by Date: Re: compare two dates MMDDYYYY
- Next by Date: Re: comments in the middle of a hash variable ?
- Previous by thread: Perl Rename function unreliable?
- Next by thread: Re: Perl Rename function unreliable?
- Index(es):
Relevant Pages
|