Perl Rename function unreliable?

Discussion in 'Perl Misc' started by Rhugga, Jul 23, 2005.

  1. Rhugga

    Rhugga Guest

    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
     
    Rhugga, Jul 23, 2005
    #1
    1. Advertising

  2. Rhugga

    Paul Lalli Guest

    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
     
    Paul Lalli, Jul 23, 2005
    #2
    1. Advertising

  3. Rhugga

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


    Include $! in the die string.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Jul 23, 2005
    #3
  4. Rhugga

    Dave Weaver Guest

    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.
     
    Dave Weaver, Jul 25, 2005
    #4
  5. Rhugga

    Rhugga Guest

    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, Jul 26, 2005
    #5
  6. Rhugga

    Paul Lalli Guest

    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
     
    Paul Lalli, Jul 26, 2005
    #6
  7. Rhugga

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


    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Jul 26, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Turner

    FPGA output unreliable

    Andrew Turner, Aug 11, 2005, in forum: VHDL
    Replies:
    9
    Views:
    761
    Mike Treseler
    Aug 16, 2005
  2. Replies:
    1
    Views:
    793
    Scott Allen
    Jul 12, 2005
  3. xyZed
    Replies:
    21
    Views:
    1,994
    Alan J. Flavell
    Mar 28, 2006
  4. =?Utf-8?B?SmViQnVzaGVsbA==?=

    Unreliable Image Display in VS2003

    =?Utf-8?B?SmViQnVzaGVsbA==?=, Jun 21, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    334
    bruce barker \(sqlwork.com\)
    Jun 21, 2006
  5. James R. Saker Jr.

    Queue qsize = unreliable?

    James R. Saker Jr., Aug 6, 2004, in forum: Python
    Replies:
    4
    Views:
    450
    Jacob Hallen
    Aug 10, 2004
Loading...

Share This Page