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
In reply to Re: Sequentially numbering output files rather than overwriting an existing file
by kcott
in thread Sequentially numbering output files rather than overwriting an existing file
by TJCooper
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |