http://www.perlmonks.org?node_id=736574

pstone has asked for the wisdom of the Perl Monks concerning the following question:

Greetings!

I've found this question before but I'm no understanding the process to completing this successfully.

My problem is this... take a look at http://www.disksleeves.com/, choose a letter of sleeves to look at and then pick a sleeve... if you keep going forwards or backwards to the next or previous sleeve, you'll see what's happening...

The image of an old sleeve is shown before the new one pops up HOWEVER the script has the command to show the .GIF being written AFTER the write command...

naturally, this is apparently a common problem yet I can't solve it. Wait doesn't work. FLOCK doesn't do anything - etc...

The code is basically:

---

$newimage->copyMerge($watermark, 30, 165, 0, 0, 350, 80, 15);

$maxtotal = 30;
$totalnum = 0;

open (xx,"<$cascade");
@totalnum = <xx>;
close (xx);

$totalnum = @totalnum[0];
$totalnum ++;

if ($totalnum > $maxtotal) {
    $totalnum = 0; 
}

open (xx, ">$cascade") or die("Cannot open file for writing");
print xx "$totalnum\n";
close (xx);

$temppic = "/home/u4/dat3/html/dsa/temppics/$totalnum.gif";

open(PICTURE,">$temppic") or die("Cannot open file for writing");
flock(PICTURE, LOCK_EX);
binmode PICTURE;
print PICTURE $newimage->gif;
close PICTURE;

print "<img src=\"/dsa/temppics/$totalnum.gif\" width=\"400\">
\n\n";

So natually, between "close PICTURE;" and the next "print "<img src=..."" line, there needs to be a way to delay until the CLOSE actually CLOSES!

Unfortunately, FLOCK didn't work - I did it and still I got the quick flash of the previously stored sleeve...

NOW I've also tried to bypass the writing of a temp file altogether and spit the gif output directly to the screen but I can't get that to work as every attempt simply spits the ASCII of the gif out, even with BINMODE yet I can do it on it's own in a test .pl file - The difference there is that the test file is just spitting out the image - nothing else where as this already has html spit out and changing the content: to gif doesn't work like it does in my stand along test file.

OK - hopefully this made sense!

Thanks Peter I would rather just do that and have no