Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: File "rename" error in renaming a file.

by GrandFather (Saint)
on Oct 11, 2022 at 20:54 UTC ( [id://11147358]=note: print w/replies, xml ) Need Help??


in reply to File "rename" error in renaming a file.

Elaborating on from Marshall's comment, it looks like you found some code in a dumpster, dusted it off, shuffled the lines a little and expected it to perform some, largely unspecified, task. Maybe this is because you have stripped out code you didn't think relevant before you showed it to us? In any case, as suggested by hv, a SSCCE would help a lot.

Your code as presented doesn't do as you claim. The rename line in the loop doesn't get hit because the loop body is not executed. In fact the spurious } at the end of the rename line means the code doesn't even compile. Maybe something closer to your intent is:

use strict; use warnings; use File::Basename; use File::Spec; my $attach = "file.png"; my $filename = File::Basename::fileparse($attach); my $tempfile = File::Spec->catfile("tempdir", $filename); my $new_filepath = File::Spec->catfile("tempdir", "allfiles.png"); rename $tempfile, $new_filepath or die "Cannot rename file $tempfile to $new_filepath: $!";
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11147358]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-03-29 08:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found