Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by duelafn (Parson)
on Jan 09, 2014 at 00:46 UTC ( [id://1069890]=note: print w/replies, xml ) Need Help??


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

If you don't want to risk races, use sysopen and loop until you can create the file yourself:

#!/usr/bin/perl -w use strict; use warnings; use 5.010; use Fcntl qw/ O_CREAT O_EXCL O_WRONLY /; my $fh = open_next( "Results", ".txt" ); print $fh "Hello!\n"; sub open_next { my ($prefix, $suffix) = @_; my $number = 0; my $FH; until (sysopen($FH, ($prefix . ($number || "") .$suffix), O_WRONLY +|O_EXCL|O_CREAT)) { $number++; } return $FH; }

Good Day,
    Dean

  • Comment on Re: Sequentially numbering output files rather than overwriting an existing file
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2026-04-13 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.