Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: rotating files, is there a better way?

by coolmichael (Deacon)
on Apr 04, 2001 at 10:46 UTC ( #69569=note: print w/ replies, xml ) Need Help??


in reply to rotating files, is there a better way?

TMTOWDI - I'd be tempted to use a glob like you did but with a regex. I don't think you need to really use -e

my $pre="image"; my $post="jpg"; my @files=<$pre.*.jpg>; @files=reverse sort @files; #should work because you don't have image.10.jpg #if you do have image.10.jpg, then you will need to use #image.09.jpg for example foreach (@files) { next unless m/^$pre\.(\d)\.$post$/; #just to be sure rename_and_log($_, "$pre." . ($1 >= 8 ? 9 : $1+1) . ".$post\n"); }
Sorry it's not very readable, but it should work. I think.

Update: I like merlyn's solution better.

michael
the blue haired monk


Comment on Re: rotating files, is there a better way?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2015-07-02 03:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (27 votes), past polls