Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
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 (Curate) 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?
[Corion]: Hmmm... Weird. Maybe it needs that for doing its timers or something. Still weird.
[Corion]: But I guess I'll find out soonish, as my application seems to use Prima for more than just displaying the OpenGL output soonish ;))
[ambrus]: No, I think the timers are handled fine in the event loop, as far as I can see.
[Corion]: So far, I liked Prima quite well as it simply seems to do what I want even if it has an upside-down coordinate system. But it installs from CPAN out of the box and is cross-platform

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2016-12-09 10:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (150 votes). Check out past polls.