Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

by educated_foo (Vicar)
on Jan 08, 2014 at 17:05 UTC ( #1069835=note: print w/replies, xml ) Need Help??


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

For the first unused "$name$n.txt" file:
if (-f "$name.txt") { $n=1; $n++ while -f "$name$n.txt"; }
For one greater than the highest "$name$n.txt" file, something like kcott's solution below works.
  • Comment on Re: Sequentially numbering output files rather than overwriting an existing file
  • Download Code

Replies are listed 'Best First'.
Re^2: Sequentially numbering output files rather than overwriting an existing file
by marinersk (Priest) on Jan 08, 2014 at 18:03 UTC
    For more visually pleasing output:
    if (-f "$name.txt") { $n=1; my $fn = sprintf "%s-%05d\.txt", $name, $n; $n++ while -f $fn; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1069835]
help
Chatterbox?
SuicideJunkie replaces stale cookies with fresh on the platter on the sideboard.
[SuicideJunkie]: So, possibly interesting thing; I had that script which was using more than all the ram to open an absurdly large spreadsheet. I set it up to spin overnight nightly, so it stopped releasing memory since it was never fully exited.

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2017-04-26 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (491 votes). Check out past polls.