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 |