I have a calendaring system which I tinker with from time to time and I make PDF reports of schedules and such. What I did was make the text into a POD format, then use POD::Pdf (well, a hacked up version). But, that may not fit your needs :) I have used some other PDF tooks in the past and suggest trying a few to see what is best for your app.

As for the filenames. Is the 'user' actually logged in (via some way you have an equiv of REMOTE_USER)? I have used things like $ENV{REMOTE_USER}.$$.file.ext for simple anti-race names. I also use the following to generate a random name:

my @set = ('a' .. 'z', 'A' .. 'Z'); my $length = 8; # Change length if desired my $random = join "" => map {$set [rand @set]} 1 .. $length; my $tmp_file = $random . "." . $$ . ".ext";

Many people have their own way to get a unique name. I tend to like adding a login name (if available), the PID (assuming I will unlink() the file when done), and some random string. If you are extra paranoid (or extra careful :) you could also add a sempahore file with the name of your temp file, and lock it. If you can't get a lock on it, then the name must be in use and you can generate another.

Cheers,
KM


In reply to Re: Avoiding race conditions by KM
in thread Avoiding race conditions by swiftone

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.