Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Sequentially numbering output files rather than overwriting an existing file

by kcott (Archbishop)
on Jan 08, 2014 at 15:34 UTC ( [id://1069822]=note: print w/replies, xml ) Need Help??


in reply to Sequentially numbering output files rather than overwriting an existing file

G'day TJCooper,

Here's one way you might go about this:

#!/usr/bin/env perl -l use strict; use warnings; use autodie; my $highest = 0; my $re = qr{pm_1069813_results(\d+)\.txt}; opendir my $dh, '.'; map { /$re/ and $1 > $highest and $highest = $1 } readdir $dh; closedir $dh; my $next_file = 'pm_1069813_results' . ++$highest . '.txt'; print "Next file: $next_file";

Output:

Next file: pm_1069813_results4.txt

Current files:

$ ls -1 pm_1069813_results*.txt pm_1069813_results1.txt pm_1069813_results2.txt pm_1069813_results3.txt

-- Ken

Replies are listed 'Best First'.
Re^2: Sequentially numbering output files rather than overwriting an existing file
by TJCooper (Beadle) on Jan 08, 2014 at 17:01 UTC
    Interesting way of going about it. Thank you!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-25 16:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found