Perl Rename function unreliable?

Has anyone experienced problems using perl rename() function? We have
seen odd results using 3 different versions of perl. 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. 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)

Advertisements

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.

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.

Advertisements

Guest

"Rhugga" <> wrote:
> Has anyone experienced problems using perl rename() function? We have
> seen odd results using 3 different versions of perl. 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.

What message does it fail with?
> 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.
>
> I'm using the rename command as follows:
>
> rename( $oldfile, $newfile) || die "Unable to rename $oldfile, manual
> intervention required.";

On 22 Jul 2005 16:35:14 -0700, Paul Lalli <> wrote:
> Rhugga wrote:
> >
> > `/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:

Also, if $oldfile or $newfile contain spaces, the command will fail to
do what you're expecting anyway.

Well, I thought it was pretty obvious what the odd resutls were, some
files were not getting renamed. I also post more than enough info even
to glean any possible problem. Regardless, the subject said has anyone
seen problems with rename. This if so, I can entertain a preivate
dialog with them directly. That is what mailing lists are for. (At
least they were 15 years ago when I first started using them, including
this list)

Obviously if the previously posted code was dying, then yes, it is
returning false.

We have moved forward with some code written in C, didn't have time to
dabble further in the matter.

Rhugga wrote:
> Well, I thought it was pretty obvious what the odd resutls were,

What odd results? What are you talking about? Please quote some
context when composing a reply.

Have you seen the Posting Guidelines for this group yet?
> some files were not getting renamed.

Of course you thought that was obvious - you're the one running the
program. You did not, however, specify exactly what was going wrong in
your program when you composed your message.
> I also post more than enough info even
> to glean any possible problem.

Really? Then why do you suppose two or three people had to ask you for
more information?
> Regardless, the subject said has anyone
> seen problems with rename. This if so, I can entertain a preivate
> dialog with them directly. That is what mailing lists are for. (At
> least they were 15 years ago when I first started using them, including
> this list)

Ah, you are under the mistaken impression that you posted to a mailing
list. You did not. You posted to a Usenet newsgroup. Entering a
private dialog is very much the antithesis of the point of newsgroups
such as these. The point of this newsgroup is to *publicly* help debug
Perl problems, so that other people can see the solutions and learn
from them, both now and in the future.

> Obviously if the previously posted code was dying, then yes, it is
> returning false.

Not once did you say your code was dying. That's what we wanted to
know. Again, just being obvious to you does not mean we can read your
mind to determine the results.
> We have moved forward with some code written in C, didn't have time to
> dabble further in the matter.

Mmm, interesting approach. Don't bother finding out what's wrong,
don't bother learning something. Just work around the issue. Well
done.

Guest

"Rhugga" <> wrote:
> Well, I thought it was pretty obvious what the odd resutls were, some
> files were not getting renamed.

That is not at all odd. It is only odd if the resulting error code/message
doesn't elucidate why they were not getting renamed.
> I also post more than enough info even
> to glean any possible problem.

Except $!, which is the only thing that really mattered.
> Regardless, the subject said has anyone
> seen problems with rename. This if so, I can entertain a preivate
> dialog with them directly. That is what mailing lists are for.

This is not a mailing list, dumbass.
> (At
> least they were 15 years ago when I first started using them, including
> this list)

This is still not a mailing list, dumbass.
>
> Obviously if the previously posted code was dying, then yes, it is
> returning false.

Yes, that would be almost obvious. But you never said the previously
posted code was dying. You said you were seeing "odd results".

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!