Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Perl Rename function unreliable?

Reply
Thread Tools

Perl Rename function unreliable?

 
 
Rhugga
Guest
Posts: n/a
 
      07-22-2005
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)

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.";

Is using this any less robust:

`/usr/bin/mv $oldfile $newfile`;

Thx,
CC

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      07-22-2005
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

 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      07-23-2005
"Rhugga" <(E-Mail Removed)> 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.";


Include $! in the die string.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
Dave Weaver
Guest
Posts: n/a
 
      07-25-2005
On 22 Jul 2005 16:35:14 -0700, Paul Lalli <(E-Mail Removed)> 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.


 
Reply With Quote
 
Rhugga
Guest
Posts: n/a
 
      07-26-2005

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.

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      07-26-2005
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.

Paul Lalli

 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      07-26-2005
"Rhugga" <(E-Mail Removed)> 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".


Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rename of FileName using PERL Laarni Perl Misc 2 09-17-2008 02:11 PM
Rename Perl Process Wolfgang Hennerbichler Perl Misc 8 08-24-2007 06:23 AM
how to use Perl to rename the filenames and directory names under current and subdirectories recursively? lucy Perl Misc 6 09-03-2004 06:27 AM
Perl: exec function with rename and Java Andy K Perl Misc 0 05-27-2004 04:16 PM
New To Perl :- Help with "rename" and "File locking" Hugz Perl 3 02-25-2004 06:21 AM



Advertisments